Boxing Conversion
If you try to assign to a boxed type like Integer
from some
code that gives you the unboxed version like int
, then Java will
automatically do that conversion.1
void main() {
int x = 5;
Integer y = x;
IO.println(x);
IO.println(y);
}
-
This might feel obvious, but this is one of the few places in Java where the type of something "magically" changes.
int
andInteger
,char
andCharacter
, etc. are different types. ↩