1

I know how boxing is done. For example, when you write Integer a = 4, Integer.valueOf(int) is being called. Likewise, can i see the implementation code for unboxing as well?

Update : It is answered in the suggested question.

javaAndBeyond
  • 520
  • 1
  • 9
  • 26
  • Both the answer there and the one given here explain that unboxing is typically done with `intValue()` (or the corresponding method for that particular type). It also links to the very specific chapter in the JLS. There's nothing else to it. – Sotirios Delimanolis Nov 19 '15 at 03:37
  • The linked JLS points to the right info. But its in the comments, not in answers. I think this should not be marked as duplicate, or may be this answer needs to be added there. – javaAndBeyond Nov 19 '15 at 03:43
  • I don't understand what you're not seeing. It's right there in the body of the [accepted answer](http://stackoverflow.com/a/22648696/438154). _The reverse is the following: `int n = Integer.valueOf(42);` which becomes [...], ie. `intValue()` is used_. – Sotirios Delimanolis Nov 19 '15 at 03:47
  • My bad. I got confused. – javaAndBeyond Nov 19 '15 at 03:56

1 Answers1

1

In such cases,intValue() gets called to get the primitive value.

Integer a= new Integer(4);
int val = a.intValue();

Like the integer, all the wrapper classes have this method to get it's primitive value.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307