Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added JLS quotes

...

The use of raw types is allowed only as a concession to compatibility of legacy code. The use of raw types in code written after the introduction of genericity into the Java programming language is strongly discouraged. It is possible that future versions of the Java programming language will disallow the use of raw types.

If a parameterized type tries to access an object that is not of the parameterized type, heap pollution results. For instance, consider the code snippet below.

Code Block

List l = new ArrayList<Integer>();
List<String> ls = l; // produces unchecked warning

However, one should not rely on unchecked warnings to implement this rule. According to [JLS 05]:

Note that this does not imply that heap pollution only occurs if an unchecked warning actually occurred. It is possible to run a program where some of the binaries were compiled by a compiler for an older version of the Java programming language, or by a compiler that allows the unchecked warnings to suppressed. This practice is unhealthy at best.

Noncompliant Code Example

...