display | more...

A class whose sole function is to provide a wrapper around the functionality of something else. In particular, Java's types are split up into two - primitive types, and reference types (i.e. objects and arrays). This pragmatism is slightly frowned upon by OOP purists, but is considered necessary for performance reasons.

Unfortunately Java distinguishes between reference and primitive types in many places. In particular, the polymorphism used in Java is based upon inheritance and the class hierarchy. This means that methods which want to accept arguments of arbitrary type, general container classes, and the like, have to work with Objects. Wrapper classes are used to encapsulate values of primitive types in objects, so that they can be passed around in the same manner.

An example:

int x = 42;  // primitive
Integer xx = new Integer(42);  // object
/* ... */
int y = xx.intValue(); // primitive again

Log in or register to write something here or to contact authors.