Passing null to overloaded methods

Assume we have an overloaded method that looks like this:

public String retrieveValue(String text) {
    return text;

public int retrieveValue(int number) {
    return number;

Pretty nice overloading, eh?! What could go wrong, for retrieveValue(null) method? In the above code, nothing, because the method with the String signature will be invoked, as the one with the int signature is just of type primitive, so, it’s almost obvious for the compiler.

However, can you imagine what would happen, if the second method accepted an argument of Integer?

public String retrieveValue(String text) {
    return text;

public int retrieveValue(Integer number) {
    return number;

Integer is the wrapper class of int and what generally stands for the wrapper classes of primitives is that they can also accept null values. So, calling retrieveValue(null) in this case will just confuse the compiler, ‘cuz it’s just ambiguous for him which method to pick up, since both of them can accept a null value argument.

Therefore, there will be a compilation error of:

Ambiguous method call. Both 
retrieveValue (String) in TestClass and
retrieveValue (Integer) in TestClass match



How to solve Could not reserve enough space for object heap

Apparently, something was going wrong with the VM arguments I was providing, but to my surprise, it was nothing that I could ever imagine.

So, I setup a tomcat server in intellij and provided a few VM options in the Tomcat’s configuration part, in intellij. When everything was setup and I tried starting the server, I got the following error:

Error occurred during initialization of VM
Could not reserve enough space for object heap

Many sources over the net, unfortunately misdirected me, cuz everything seemed to be configured properly.

In the end, I took a look again in the VM options I pasted to my intellij.

Oh, man I was defining a max memory option of 10g, whereas my machine only had 8g!

Lesson learned

Don’t blindly copy whatever you find on your way.

Closing Quote

Always filter what others feed you with.