java generics javac unchecked

¿Por qué javac se queja de genéricos no relacionados con los argumentos de tipo de la clase?



generics unchecked (1)

De JLS 4.8 Tipos sin formato

El uso de tipos sin formato solo se permite como una concesión a la compatibilidad del código heredado. Se desaconseja el uso de tipos sin formato en código escrito después de la introducción de genéricos en el lenguaje de programación Java.

y

El tipo de constructor (§8.8), método de instancia (§8.4, §9.4) o campo no estático (§8.3) M de un tipo sin formato C que no se hereda de sus superclases o superinterfaces es el tipo sin formato que corresponde a la eliminación de su tipo en la declaración genérica correspondiente a C.

Lo cual, si lo lee detenidamente, implica que todos los tipos se borran , no solo el tipo que omitió.

Lea los comentarios en el código en orden, los detalles de la pregunta están allí.
¿Por qué está sucediendo esta diferencia?
Por favor, indique el JLS si es posible.

import java.util.*; /** * Suppose I have a generic class * @param <T> with a type argument. */ class Generic<T> { // Apart from using T normally, T paramMethod() { return null; } // the class'' interface also contains Generic Java Collections // which are not using T, but unrelated types. List<Integer> unrelatedMethod() { return null; } } @SuppressWarnings("unused") public class Test { // If I use the class properly (with qualified type arguments) void properUsage() { Generic<String> g = new Generic<String>(); // everything works fine. String s = g.paramMethod(); List<Integer> pos = g.unrelatedMethod(); // OK error: incompatible types: List<String> := List<Integer> List<String> thisShouldErrorCompile = g.unrelatedMethod(); } // But when I use the raw type, *ALL* the generics support is gone, even the Collections''. void rawUsage() { // Using Generic<?> as the type turns fixes the warnings below. Generic g = new Generic(); // OK error: incompatible types: String := Object String s = g.paramMethod(); // WTF warning: unchecked conversion: List<Integer> := raw List List<Integer> pos = g.unrelatedMethod(); // WTF warning: unchecked conversion: List<String> := raw List List<String> thisShouldErrorCompile = g.unrelatedMethod(); } }

Nota al margen

Originalmente encontré esto en IntelliJ IDEA, pero supongo que ese compilador es compatible con javac porque cuando compilé el código anterior con lo siguiente, me dio los mismos errores / advertencias.

$ javac -version javac 1.7.0_05 $ javac Test.java -Xlint:unchecked ... $ javac Test.java -Xlint:unchecked -source 1.5 -target 1.5 ...