aspose file tools*
The moose likes Beginning Java and the fly likes Wrapper Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wrapper Class" Watch "Wrapper Class" New topic
Author

Wrapper Class

Rameshwar Soni
Ranch Hand

Joined: Feb 03, 2011
Posts: 247
Is there any difference between these two below ? And which one is recommended ?
(1)
(2)

Thanks in advance
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
That latter. That is because the value might already have been used, and you might save memory and object construction overhead by re-using the old object. This only works for immutable classes. The details are in the API documentation.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

The former gets turned into the second one by the compiler. There is no difference between the two.

@Campbell: I think you're confused by using new Integer(250) versus Integer.valueOf(250). In that comparison you're absolutely right - valueOf is definitely preferred.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper Class