Before JAVA 5.0, working with primitive types required additional work for converting the primitive types into wrapper classes and vice – versa.
Example :
Example :
//covert primitive to wrapper int intPri1 = 10; Integer intObj1 = new Integer(intPri1); //convert wrapper to primitive Integer intObj2 = new Integer(10); int intPri2 = intObj2.intValue();
After JAVA 5.0 : Provided Auto Boxing/Unboxing, conversion of primitive types (int, float, double etc.) to their object equivalents (Integer, Float, Double,...) will be automatically, this mechanism called Auto boxing.
and also wrapper types are automatically converted into their primitive equivalents (Unboxing).
Example:
//covert primitive to wrapper - Auto boxing int intPri1 = 10; Integer intObj1 = intPri1; //convert wrapper to primitive - Unboxing Integer intObj2 = new Integer(10); int intPri2 = intObj2;
No comments:
Post a Comment