Languagemedium0-2 years
What is the difference between int and Integer? Where does autoboxing bite?
int is a primitive value: fast, never null, no identity. Integer is an object: nullable, allocated, compared with equals. Autoboxing converts silently — and unboxing a null Integer throws a NullPointerException, often inside an arithmetic expression far from the field.
PreviousWhy are strings immutable in Java, and what does that cost?Next What changed in switch, and why should a sealed switch have no default?