Jesper Young wrote:
Jacob Sonia wrote:int a =0;
if(a!= null)
why does it throw compiler error and not do autoboxing
Because it would not make much sense. What would you expect; that the int a is boxed into an Integer object, and that that Integer object would be compared with null? The result would always be false.
Jacob,
I think for boxing operation, the compiler will intValue(), so when you write below code
compiler behind the scense use intValue() method
becoz of that, it generates run-time exception at second line (NullPointerException)
and for un-boxing, compiler will use valueOf() method, therefore the following code :
will become
Hope this helps