Java Primitive Types: int vs. Integer

前端 未结 6 1376
予麋鹿
予麋鹿 2020-12-03 14:02

I am confused about when to use primitive vs. non-primitive(?) types (i.e. int vs. Integer) in Java. I realize that in some places you can\'t use primitive types (for exampl

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 14:45

    There is a slight penalty for converting between the types (autoboxing). Also int will have a bit less overhead so I would always go with int if you can.

    Also see this question: When to use primitive and when reference types in Java

提交回复
热议问题