A little more on this fabulous subject:

1 - From a private mail

This is true from version Java 1.5 and above, not true below.

2 - From Sun forum

There's a difference. In the second case the new operator isn't used.
Instead the reference of a pre-created Integer object is assigned to
foo.

If, instead of 10, the number would be outside the range of -128 to
127 then the two lines would effectively be the same. Also in the
second case a new Integer object would've been created.

Why this difference of treatment between small integers and huge
integers:
Optimization. Those numbers are cached because they're more likely to
be used than a number such as 672854.


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to