Why do people still use primitive types in Java?

后端 未结 21 2492
暗喜
暗喜 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

    Primitive types are much faster:

    int i;
    i++;
    

    Integer (all Numbers and also a String) is an immutable type: once created it can not be changed. If i was Integer, than i++ would create a new Integer object - much more expensive in terms of memory and processor.

提交回复
热议问题