Why do people still use primitive types in Java?

后端 未结 21 2488
暗喜
暗喜 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:12

    Primitive types have many advantages:

    • Simpler code to write
    • Performance is better since you are not instantiating an object for the variable
    • Since they do not represent a reference to an object there is no need to check for nulls
    • Use primitive types unless you need to take advantage of the boxing features.

提交回复
热议问题