Autoboxing: So I can write: Integer i = 0; instead of: Integer i = new Integer(0);

后端 未结 9 1219
猫巷女王i
猫巷女王i 2020-12-01 21:04

Autoboxing seems to come down to the fact that I can write:

Integer i = 0; 

instead of:

Integer i = new Integer(0);
         


        
9条回答
  •  [愿得一人]
    2020-12-01 21:40

    Adding to Lim's comment, primitives are stored on the stack, and primitive-wrappers, as objects, are stored on the heap... There are subtle implications due to this.

提交回复
热议问题