I found an example where I cannot find the number of boxing and unboxing in the Java code below :
Integer x = 5;
int y = x + x;
I would say that there is one type of unboxing (int y = x + x
), but I am not sure about that. Is there any boxing as well?
There is one boxing in Integer x = 5
. The int
5 is boxed to Integer
.
There are two un-boxings in int y = x + x
: Integer x
is unboxed twice.