When declaring this in a class:
Integer i = 9;
It complies now due to autoboxing I believe, is i
considered primitive data type?
No, the type of i
is still Integer
(the reference type) - that's how it's declared, after all. The fact that it happens to be initialized using an int
is entirely separate from the type of the variable. The literal 9
is a value of type int
, but it's boxed into an Integer
.
The code is equivalent to:
Integer i = Integer.valueOf(9);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With