Versions Compared

Key

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

Heap pollution occurs when a variable of a parameterized type references an object that is not of that parameterized type. (For more information on heap pollution, see The Java Language Specification (JLS), §4.12.2., "Variables of Reference Type," [JLS 2014]).

Mixing generically typed code with raw typed code is one common source of heap pollution. Generic types were unavailable prior to Java 5, so popular interfaces such as the Java Collection Framework relied on raw types. Mixing generically typed code with raw typed code allowed developers to preserve compatibility between nongeneric legacy code and newer generic code but also gave rise to heap pollution. Heap pollution can occur if the program performs some operation involving a raw type that would give rise to a compile-time unchecked warning.

...

[Bloch 2008]

Item 23, "Don't Use Raw Types in New Code"

[Bloch 2007] 

[Bloch 2005]

Puzzle 88, "Raw Deal"

[Darwin 2004]

Section 8.3, "Avoid Casting by Using Generics"

[JavaGenerics 2004]

 

[JLS 2005]

Chapter 5, "Conversions and Promotions"
§4.8, "Raw Types"

§5.1.9, "Unchecked Conversion"

[Langer 2008]

Topic 3, "Coping with Legacy"

[Naftalin 2006]

Chapter 8, "Effective Generics"

[Naftalin 2006b]

"Principle of Indecent Exposure"

[Schildt 2007]

"Create a Checked Collection"

[Tutorials 2008]

"Heap Pollution"

...