4.2 Converting Wrapper Types to Primitives
Just as Tiger converts
primitives to wrapper types as needed, the reverse
is also true. Like boxing, unboxing involves little effort on
the part of the
programmer.
4.2.1 How do I do that?
Here's some more simple code that does both boxing and unboxing, all
without any special instruction:
Pretty simple, isn't it?
// Boxing
int foo = 0;
Integer integer = foo;
// Simple Unboxing
int bar = integer;
Integer counter = 1; // boxing
int counter2 = counter; // unboxing
4.2.2 What about...
...null value assignment? Since null is a legal value for an object, and
therefore any wrapper type, the following code is legal:
Integer i = null;int j = i;
i is assigned null (which is legal), and then i is unboxed into j. However,
null isn't a legal value for a primitive, so this code throws a
NullPointerException.