Why do people still use primitive types in Java?

后端 未结 21 2532
暗喜
暗喜 2020-11-22 15:11

Since Java 5, we\'ve had boxing/unboxing of primitive types so that int is wrapped to be java.lang.Integer, and so and and so forth.

I see

21条回答
  •  死守一世寂寞
    2020-11-22 15:18

    Autounboxing can lead to hard to spot NPEs

    Integer in = null;
    ...
    ...
    int i = in; // NPE at runtime
    

    In most situations the null assignment to in is a lot less obvious than above.

提交回复
热议问题