design patterns - What is a wrapper class? - Stack Overflow
Why are there wrapper classes in Java? - Stack Overflow
Why use Wrapper Classes over Primitive Datatypes?
ELI 5, what is a "wrapper"
Videos
In general, a wrapper class is any class which "wraps" or "encapsulates" the functionality of another class or component. These are useful by providing a level of abstraction from the implementation of the underlying class or component; for example, wrapper classes that wrap COM components can manage the process of invoking the COM component without bothering the calling code with it. They can also simplify the use of the underlying object by reducing the number interface points involved; frequently, this makes for more secure use of underlying components.
Just what it sounds like: a class that "wraps" the functionality of another class or API in a simpler or merely different API.
See: Adapter pattern, Facade pattern
Several possible reasons:
- So that a null value is possible
- To include in a Collection
- To treat generically / polymorphically as an Object along with other Objects
Am example of when wrappers are used would be in Collections, you can have an ArrayList<Integer>, but not an ArrayList<int> same with HashMaps etc. To get type safety we use generics and generics need objects not primitives.