File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrappers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrappers" Watch "Wrappers" New topic


James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Both t and I are reference variables, holding the memory location of their respective objects.
Using final(for the test object) ,implies that the contents of the reference cannot be changed BUT the object state can be changed.
Isn't it the same for Integer reference. If not why??

Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Because the increment operation tries to unbox the Integer, increment it, create a new Integer with that value and assign it to I.

Edit: wrapper classes are immutable

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
kshitij dogra
Ranch Hand

Joined: Dec 28, 2008
Posts: 39
What is actually happening is that the Integer i , is being unboxed and then incremented , and then again boxed back to the value.......

SCJP 5.0 - 100%
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

got it..
I agree. Here's the link:
subject: Wrappers