can we change wrapper to primitive ?if not then what is happening in this code
int I = Integer.valueOf(46);
System.out.println(I);
I am not getting any error.
Yes, this is called unboxing:
Integer boxed = 10; // Boxing
int unboxed = boxed; // Unboxing
Boxing conversions are described in JLS 5.1.7; unboxing conversions are described in JLS 5.1.8.
Note that if you try to unbox a null
reference, a NullPointerException
will be thrown:
Integer boxed = null;
int unboxed = boxed; // NPE
See more on this question at Stackoverflow