Java - Wrapper Classes
Wrapper Classes
Integer x = 10; // boxing
int y = x; // unboxing (beware null!)
Use wrappers when generics/collections require reference types, or to represent nullability.
Try it
- Demonstrate
NullPointerException
from unboxing a nullInteger
and then guard against it. - Store primitives vs wrappers in a list and note the boxing overhead implications.