Primitive wrapper class

From Seo Wiki - Search Engine Optimization and Programming Languages

Jump to: navigation, search

A primitive wrapper class in the Java programming language is one of eight classes provided in the Template:Javadoc:SE package to provide object methods for the eight primitive types. All of the primitive wrapper classes in Java are immutable. J2SE 5.0 introduced autoboxing of primitive types into their wrapper object, and automatic unboxing of the wrapper objects into their primitive value—the implicit conversion between the wrapper objects and primitive values.

Wrapper classes are used to represent primitive values when an Template:Javadoc:SE is required. The wrapper classes are used extensively with Template:Javadoc:SE classes in the Template:Javadoc:SE package and with the classes in the Template:Javadoc:SE reflection package.

The primitive wrapper classes and their corresponding primitive types are:

Primitive type Wrapper class Constructor Arguments
byte Template:Javadoc:SE byte or String
short Template:Javadoc:SE short or String
int Template:Javadoc:SE int or String
long Template:Javadoc:SE long or String
float Template:Javadoc:SE float, double or String
double Template:Javadoc:SE double or String
char Template:Javadoc:SE char
boolean Template:Javadoc:SE boolean or String

The Byte, Short, Integer, Long, Float, and Double wrapper classes are all subclasses of the Template:Javadoc:SE class.


Although it is not a wrapper class, the Template:Javadoc:SE class is similar in that it provides an object representation of the void return type. The Void class is an uninstantiable placeholder class used by the Template:Javadoc:SE API to hold a reference to the Template:Javadoc:SE object representing the Java keyword void..

Atomic wrapper classes

With Java 5.0, additional wrapper classes were introduced in the Template:Javadoc:SE package. These classes are mutable and cannot be used as a replacement for the regular wrapper classes. Instead, they provide atomic operations for addition, increment and assignment.

The atomic wrapper classes and their corresponding types are:

Primitive type Wrapper class
int Template:Javadoc:SE
long Template:Javadoc:SE
boolean Template:Javadoc:SE
V Template:Javadoc:SE

The AtomicInteger and AtomicLong classes are subclasses of the Number class. The AtomicReference class accepts the type parameter V that specifies the type of the object reference. (See "Generics in Java" for a description of type parameters in Java).

See also

Personal tools

Served in 0.051 secs.