Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Integer.valueOf( int i ) vs. Integer.valueOf( String s )?

807591Apr 22 2008 — edited Apr 22 2008
an inspection of the implementation ( 1.6.0_04 ) indicates that valueOf( int i ) and valueOf( String s ) differ in an interesting way.

the former attempts to return an Integer from the internal cache, while the latter always constructs a new Integer after parsing. naively, one might expect valueOf( String s ) to parse to a primitive, then invoke valueOf( int i ).

i'm guessing the original implementation is preserved to avoid breaking code that depends on unique Integer objects being returned by this method, but i'm not certain.

am i right, or is this an oversight, or am i missing something (again)?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 20 2008
Added on Apr 22 2008
5 comments
520 views