The following code leads to a compiler warning without warning -
{
List<String> first = first((Class)Integer.class);
}
private <T> List<String> first(Class<T> clazz) { return null; }
However, there are no warnings in the following code -
{
List<String> second = second((Class)Integer.class);
}
private List<String> second(Class<?> clazz) { return null; }
Only three warnings, the first two I expect, but the third does not make sense -
$ javac Test1.java -Xlint
Test1.java:6: warning: [unchecked] unchecked conversion
found : java.lang.Class
required: java.lang.Class<T>
List<String> first = first((Class)Integer.class);
^
Test1.java:6: warning: [unchecked] unchecked method invocation: <T>first(java.lang.Class<T>) in Test1 is applied to (java.lang.Class)
List<String> first = first((Class)Integer.class);
^
Test1.java:6: warning: [unchecked] unchecked conversion
found : java.util.List
required: java.util.List<java.lang.String>
List<String> first = first((Class)Integer.class);
^
3 warnings
Compiler Version -
$ javac -version
javac 1.6.0_45
My question is: why is there a third compiler error?
patch source
share