Search code examples
javaautoboxing

Unboxing Integer cast from null


What is the value of i when you execute the code below and why?

int i = (Integer)null;

Solution

  • See jls5.1.8:

    At run time, unboxing conversion proceeds as follows:

    ...

    If r is null, unboxing conversion throws a NullPointerException