One thing my professor failed to explain was whether or not wrapper classes (such as Integer.*
or Double.*
) took up more RAM space because they have the format of an object reference and not a primitive data type.
Asked
Active
Viewed 75 times
0

Colby Stahl
- 67
- 7
-
3Yes, boxed types take up more space than unboxed primitives . I'm pretty sure this is always true. – Carcigenicate Dec 08 '16 at 01:43
-
see this answer http://stackoverflow.com/a/258150/2310289 – Scary Wombat Dec 08 '16 at 01:50
1 Answers
1
Yes, boxed typed take more space because - of the pointer referencing it (often 64-bit on modern, non-embedded architectures) - of the extra fields in the native implementation of the Object (such as, possibly, reference to the class, id, etc.)
However, under the hood, at least in theory, JVM/Hotspot may be able to optimize some boxed types based on their utilization.

Roberto Attias
- 1,883
- 1
- 11
- 21