The Java compiler applies unboxing when an object of a wrapper class is:
- Passed as a parameter to a method that expects a value of the corresponding primitive type.
- Assigned to a variable of the corresponding primitive type.
So, as there was a suitable method for Integer class, which is void go(Number n)
because Number
class is super class of Integer
and this method accepts Integer
objects as well.
So compiler didn't need to unbox the Integer
to int
.