When you declare Integer i = 9 in java, is i considered to be primitive type due to autoboxing?

When declaring this in a class:

Integer i = 9;

It complies now due to autoboxing I believe, is i considered primitive data type?

Jon Skeet
people
quotationmark

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);

people

See more on this question at Stackoverflow