...
According to the Java Language Specification [JLS 052005] section 4.8 "Raw Types":
...
It is insufficient to rely on unchecked warnings alone to detect violations of this guideline. According to the Java Language Specification [JLS 052005] section 4.12.2.1 "Heap Pollution":
...
Extending legacy classes and generifying the overriding methods is not a panacea as this is made illegal by the Java Language Specification [JLS 052005]. It is best to avoid mixing generic and non-generic code.
...
EX1: Raw types must be used in class literals. For example, as List<Integer>.class
is illegal, it is permissible to use the raw type List.class
. [Bloch 082008]
EX2: The instanceof
operator cannot be used with generic types. It is permissible to mix generic and raw code in such cases. [Bloch 082008]
Code Block |
---|
if(o instanceof Set) { // Raw type Set<?> m = (Set<?>) o; // Wildcard type // ... } |
...
References
Wiki Markup |
---|
\[[Langer 082008|AA. Java References#Langer 08]\] Topic 3, "[Coping with Legacy|http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#Topic3]" [[Bloch 082008|AA. Java References#Bloch 08]\] Item 23: "Don't use raw types in new code" [[Bloch 072007|AA. Java References#Bloch 07]\] Generics, 1. "Avoid Raw Types in New Code" \[[Naftalin 06b2006b|AA. Java References#Naftalin 06b]\] "Principle of Indecent Exposure" [[JLS 052005|AA. Java References#JLS 05]\] 4.8 "Raw types" and 5.1.9 "Unchecked Conversion" |
...