Get Time
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat  | Threaded  | Tree
Previous Thread  |  Next Thread
Error in boxing description | Reply

Thanks for the nice overview of 1.5. There is an error in the boxing description.

The tutorial says:

For example, in Java 1.5 this is perfectly valid:

Integer value = 26;

And has the same effect as writing:

Integer value = new Integer (26);

This is not correct as the language spec says this boxing operation must return Integers which are equal to other auto boxed Integers with the same value for values in the range -128 to 127. (see section 5.1.7 Boxing Conversion in "The Java Language Specification, Third Edition")

The equivalent code is really:

Integer value = Integer.valueOf (26);

The Integer.valueOf(int) static method is free to return a reference to an existing Integer that has the same value. This method enforces the language requirement for values between -128 and 127.
Subject Author Date
Error in boxing description pgc Jul 17, 2008 at 10:25 PM EDT
Re: Error in boxing description wrick Jul 20, 2008 at 9:06 PM EDT
Re: Error in boxing description slex Jul 21, 2008 at 3:35 AM EDT