Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Wiki Markup
            A boxing conversion converts the value of a primitive type to the corresponding value of the reference type. One example is the automatic conversion from {{int}} to {{Integer}} \[[JLS 2005|AA. Bibliography#JLSReferences#JLS 05]\]. This is convenient in cases where an object parameter is required, such as with collection classes like {{Map}} and {{List}}. Another use case is for interoperation with methods that require their parameters to be object references rather than primitive types. Automatic conversion to the resulting wrapper types also reduces clutter in code.

...

Wiki Markup
The language's type checking guarantees that only values of type {{Short}} can be inserted into the {{HashSet}}.  Nevertheless, programmers are free to attempt to remove an object of _any_ type because {{Collections<E>.remove()}} accepts an argument of type {{Object}} rather than of type {{E}}. Such behavior can result in unintended object retention or memory leaks \[[Techtalk 2007|AA. Bibliography#TechtalkReferences#Techtalk 07]\]. 

Compliant Solution

Objects removed from a collection must share the type of the elements of the collection. Numeric promotion and autoboxing can produce unexpected object types. This compliant solution uses an explicit cast to short that matches the intended boxed type.

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="644fd95685534aad-6f58ac54-4ac04880-8e7187f2-790f21079cbc58dbd53cfecf"><ac:plain-text-body><![CDATA[

[[Core Java 2004

AA. Bibliography#Core References#Core Java 04]]

Chapter 5

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="49e9cd22450543b8-d2a7c701-41e74893-a8f98c43-94f26ab65ff1407b8c401db7"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS References#JLS 05]]

[§5.1.7, Boxing Conversions

http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.7]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9217f223298deb2f-7fe30fd0-42f4433a-a9479f94-bc57a2c2fb9cb1193b496af1"><ac:plain-text-body><![CDATA[

[[Techtalk 2007

AA. Bibliography#Techtalk References#Techtalk 07]]

The Joy of Sets

]]></ac:plain-text-body></ac:structured-macro>

...