wrapper class

created by beaneater
(thing) by beaneater (4 y) (print)   (I like it!) Wed May 29 2002 at 21:12:40

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
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.