Page 1 of 1

Java 5 "box" and "unbox" values

PostPosted: Sat Apr 16, 2011 11:08 am
by haretu
Java5(Java1.5)and later automatically“box”
and ”unbox” values
Integer intObject = new Integer(123);
int intPrimitive = intObject;
double doublePrimitive = 123.45;
Double doubleObject = doublePrimitive;
– The advent of automatic Boxing and automatic Unboxing greatly simplifies code when using Collection and other types of objects
– Boxing and Unboxing is also important since Primitive data and Reference Type data are stored in different places; primitives representing local variables are stored on the stack while objects are stored in heap memory.