Java Primitive Types: int vs. Integer

前端 未结 6 1377
予麋鹿
予麋鹿 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:40

    Short answer: An int is a number; an Integer is a pointer that can reference an object that contains a number. Using Integer for arithmetic involves more CPU cycles and consumes more memory. An int is not an object and cannot passed to any method that requires objects (just like what you said about Generics).

提交回复
热议问题