Revision as of 14:18, 11 November 2006 editChip Zero (talk | contribs)459 edits added →Atomic wrapper classes← Previous edit | Revision as of 07:14, 13 November 2006 edit undoDoug Bell (talk | contribs)Extended confirmed users11,585 edits →Atomic wrapper classes: add statement about references being primitivesNext edit → | ||
(One intermediate revision by the same user not shown) | |||
Line 33: | Line 33: | ||
== Atomic wrapper classes == | == Atomic wrapper classes == | ||
With Java 5.0, additional wrapper classes were introduced in the {{Javadoc:SE|package=java.util.concurrent.atomic|java/util/concurrent/atomic}} package |
With Java 5.0, additional wrapper classes were introduced in the {{Javadoc:SE|package=java.util.concurrent.atomic|java/util/concurrent/atomic}} package. These classes are mutable cannot be used as a replacement for the regular wrapper classes. Instead, they provide ]s for addition, increment and assignment. | ||
The atomic wrapper classes and their corresponding primitive types are: | |||
:{| class="wikitable" | |||
! Primitive type !! Wrapper class | |||
|- | |||
| <code>int</code> || {{Javadoc:SE|java/util/concurrent/atomic|AtomicInteger}} | |||
|- | |||
| <code>long</code> || {{Javadoc:SE|java/util/concurrent/atomic|AtomicLong}} | |||
|- | |||
| <code>boolean</code> || {{Javadoc:SE|java/util/concurrent/atomic|AtomicBoolean}} | |||
|- | |||
| <code>V</code> || {{Javadoc:SE|class=AtomicReference<V>|java/util/concurrent/atomic|AtomicReference}} | |||
|} | |||
The <code>AtomicReference</code> class accepts the ] <code>V</code> that specifies the type of the object ]. (See "]" for a description of type parameters in Java.) Note that while an object type is not a primitive type, an object reference is. | |||
== See also == | == See also == |
Revision as of 07:14, 13 November 2006
A primitive wrapper class in the Java programming language is one of eight classes provided in the java.lang
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 Object
is required. The wrapper classes are used extensively with Collection
classes in the java.util
package and with the classes in the java.lang.reflect
reflection package.
The primitive wrapper classes and their corresponding primitive types are:
Primitive type Wrapper class byte
Byte
short
Short
int
Integer
long
Long
float
Float
double
Double
char
Character
boolean
Boolean
The Byte
, Short
, Integer
, Long
, Float
, and Double
wrapper classes are all subclasses of the Number
class.
Void
Although it is not a wrapper class, the Void
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 java.lang.reflect API to hold a reference to the Class
object representing the Java keyword void
.
Atomic wrapper classes
With Java 5.0, additional wrapper classes were introduced in the java.util.concurrent.atomic
package. These classes are mutable 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 primitive types are:
Primitive type Wrapper class int
AtomicInteger
long
AtomicLong
boolean
AtomicBoolean
V
AtomicReference<V>
The AtomicReference
class accepts the type parameter V
that specifies the type of the object reference. (See "Generic programming#Generics in Java" for a description of type parameters in Java.) Note that while an object type is not a primitive type, an object reference is.