For example, look at this code:
Integer myInt = new Integer(5);
int i1 = myInt.intValue();
int i2 = myInt;
System.out.println(i1);
System.out.println(i2);
As you can see, I have two ways of copying my integer value from the wrapper to the primive:
I can use unboxing,
OR
I can use the method Integer#intValue()
.
So what's the need of having a method when there is already unboxing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…