answersLogoWhite

0

Conversion of primitive data types automatically to their corresponding wrapper classes is called AutoBoxing and the reverse of this operation is called UnBoxing.

Ex:

Long L = new Long(100);

long x = L;

Now x will have a value 100.

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

RossRoss
Every question is just a happy little opportunity.
Chat with Ross
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
More answers

New to Java 5 is a feature known variously as: autoboxing, auto-unboxing, boxing, and unboxing. We'll stick with the terms boxing and unboxing. Boxing and unboxing make using wrapper classes more convenient. In the old, pre-Java 5 days, if you wanted to make a wrapper, unwrap it, use it, and then rewrap it, you might do something like this:

Integer y = new Integer(111);

int x = y.intValue();

x++;

y = new Integer(x);

System.out.println("y = " + y);

Now, with new and improved Java 5 you can say

Integer y = new Integer(111);

y++;

System.out.println("y = " + y);

Both examples produce the same output:

y = 112

And yes, you read that correctly. The code appears to be using the postincrement operator on an object reference variable! But it's simply a convenience. Behind the Scenes, the compiler does the unboxing and reassignment for you.

Note: When == is used to compare a primitive to a wrapper, the wrapper will be unwrapped and the comparison will be primitive to primitive

User Avatar

Wiki User

11y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What is AutoBoxing and UnBoxing in java 5?
Write your answer...
Submit
Still have questions?
magnify glass
imp