public class NullTernary {
public static void main(String[] args) {
// TODO Auto-generated method stub
NullTernary obj= new NullTernary();
obj.GetValue();
}
int GetValue()
{
return (true ? null : 0);
}
}
Output of running main method of above class is,
Exception in thread "main" java.lang.NullPointerException
at NullTernary.GetValue(NullTernary.java:13)
at NullTernary.main(NullTernary.java:8)
is Java auto boxing the reason for NullPointerException ( i.e. when function tries to convert null value to Integer) or some other explanation?
If auto boxing to Integer theory is correct, I was wondering why auto boxing be done when expected value in int and not Integer ?