3

Possible Duplicates:
When to use wrapper class and primitive type
What is boxing and unboxing and what are the trade offs?

Boxing basically converts primitive type to its corresponding reference type. But when do we need Boxing? Whether Wrapper class and Boxing do the same job?

Community
  • 1
  • 1
Sumithra
  • 6,587
  • 19
  • 51
  • 50
  • http://stackoverflow.com/questions/1570416/when-to-use-wrapper-class-and-primitive-type – jmj Oct 22 '10 at 08:56
  • http://stackoverflow.com/questions/13055/what-is-boxing-and-unboxing-and-what-are-the-trade-offs – jmj Oct 22 '10 at 08:58

1 Answers1

4

Autoboxing/unboxing is a pure convenience feature that allows you to assign values of a primitive type a reference of a wrapper class and vice versa, with the compiler automatically adding the code to convert between the two.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
  • really confusing then what is wrapper class? I need to know the difference b/w wrapper class & boxing – Sumithra Oct 22 '10 at 09:11
  • 1
    @Sumithra: `java.lang.Integer` is a wrapper class. Autoboxing is the language mechanism that allows you to say `Integer i = 5;` instead of `Integer i = Integer.valueOf(5);` or `Integer i = new Integer(5);` - and "Boxing" isn't an expression typically used, except perhaps as a shortening of "Autoboxing". – Michael Borgwardt Oct 22 '10 at 09:20
  • Boxing uses wrapper objects to box values rit? – Sumithra Oct 22 '10 at 09:22
  • Thanks Michael!!!I understand it now – Sumithra Oct 22 '10 at 09:25