A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Take Control of Upgrading to Yosemite
Take Control of Automating Your Mac
this week in the
Joined: Feb 03, 2011
Aug 21, 2011 06:50:54
Is there any difference between these two below ? And which one is recommended ?
Thanks in advance
Joined: Oct 13, 2005
Aug 21, 2011 07:21:26
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
Joined: Oct 27, 2005
Aug 21, 2011 07:22:21
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
. 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
subject: Wrapper Class
Sending mail through Java
problem about constructing Integer objects
How hashCode() works?
Error found in KB's pg236
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014