Wrapping the Primitive Types in Classes

   

You saw in Chapter 3, that although Java is a language based on classes, it does support a set of primitive data types that includes int, boolean, and float among others. These types are used extensively, but there are situations in which treating primitives as true Java objects would be more useful. In fact, the java.lang package includes a set of wrapper classes for the primitive data types to serve this purpose. This set consists of Boolean, Byte, Character, Double, Float, Integer, Long, and Short. Each of these classes provides an immutable object representation of its corresponding primitive type. The methods defined by the classes consist mainly of conversion and comparison operations. Each class also overrides toString() and equals() to provide an intuitive text representation and a simple equality check for wrapped values.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net