The biggest advantage of boxed primitives over the regular ones is the ability to use them in the standard Java collections. It is possible to make, say, an ArrayList<Integer>
, but not ArrayList<int>
.
Their biggest disadvantage is the costs, both in terms of memory and in terms of performance: depending on the architecture and the underlying type, the cost in terms of memory may go as much as nine times (consider boxing a byte
on a 64-bit platform). The cost in performance is twofold: you need extra cycles for unboxing every time you need the value, but more importantly, the memory footprint influence the order in which the actual memory is accessed, which may reduce the efficiency of the CPU data caching.
The other advantages/disadvantages that you have listed apply as well:
- Boxed primitives are nullable,
- You do not need to copy a value, only a reference (this saves you time and space only when the size of a reference is smaller than the size of the data, e.g. when you have a
Long
on a 32-bit platform). - Boxed primitives are harder to compare for equality/inequality.
The "defensive copying" point does not apply, because all boxed primitives in Java are immutable.