Generic code can be freely used with raw types when attempting to preserve compatibility between non-generic legacy code and newer generic code. However, using raw types with generic code will cause most Java compilers to issue "unchecked" warnings. When generic and non-generic code is used correctly, these warnings are not catastrophic, but the same warnings are issued when potentially unsafe operations are performed. If generic and non-generic code must be used together, these warnings should not be simply ignored.
According to [JLS 05]:
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.
Noncompliant Code Example
...
Wiki Markup |
---|
\[[Langer 08|AA. Java References#Langer 08]\] Topic 3, "[Coping with Legacy|http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#Topic3]"
[[Bloch 08|AA. Java References#Bloch 08]\] Item 23: "Don't use raw types in new code"
[[Bloch 07|AA. Java References#Bloch 07]\] Generics, 1. "Avoid Raw Types in New Code"
[[JLS 05|AA. Java References#JLS 05]\] 4.8 "Raw types" |