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

后端 未结 9 1271
猫巷女王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:49

    That is the idea, yes. It's even more convenient to be able to assign an Integer to an int, though.

    One could argue that autoboxing addresses a symptom rather than a cause. The real source of confusion is that Java's type system is inconsistent: the need for both primitives and object references is artificial and awkward. Autoboxing mitigates that somewhat.

提交回复
热议问题