Java – Auto boxing: so I can write: integer I = 0; Instead: integer I = new integer (0);

Automatic packing seems to come down to the fact that I can write:

Integer i = 0;

Substitute:

Integer i = new Integer(0);

Therefore, the compiler can automatically convert primitives to objects

Is that the idea? Why is this important?

Solution

You're a little simplified

Automatic boxing also works when using collections As described in sun's Java document:

Great overview of Autoboxing

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>