When should I use primitives instead of wrapping objects?

后端 未结 5 2191
逝去的感伤
逝去的感伤 2020-12-14 09:52

Actually here is a similar topic with little practical value. As far as I understand, primitives perform better and should be used everywhere except for the cases where Obje

5条回答
  •  难免孤独
    2020-12-14 10:34

    yes, primitives are faster than objects. Since java 5 you can even mix primitives and objects without manually converting one to another. The autoboxing mechanism takes care of just that.

    this means that if you put a primitive in a collection, the compiler will not complain, and convert the primitive to an object implicitly.

提交回复
热议问题