C
Christopher Benson-Manica
Consider this very simple code:
import java.util.*;
public class Test {
private static class Foo<T> {
public List<String> foo(List<String> param) {
return param;
}
}
public static void main(String[] args) {
Foo f = new Foo();
List<String> bar = f.foo(new ArrayList<String>());
}
}
f is a member of the raw type Foo, and therefore as expected the code
produces a warning about an unchecked call to foo() when compiled with
-Xlint:unchecked. What I don't understand, however, is why there is
also a warning about an unchecked conversion from java.util.List to
java.util.List<java.lang.String>. Why is the compiler unable to
determine that foo does in fact return a List<String> and not a raw
List? Or is the compiler output simply overstating the case?
import java.util.*;
public class Test {
private static class Foo<T> {
public List<String> foo(List<String> param) {
return param;
}
}
public static void main(String[] args) {
Foo f = new Foo();
List<String> bar = f.foo(new ArrayList<String>());
}
}
f is a member of the raw type Foo, and therefore as expected the code
produces a warning about an unchecked call to foo() when compiled with
-Xlint:unchecked. What I don't understand, however, is why there is
also a warning about an unchecked conversion from java.util.List to
java.util.List<java.lang.String>. Why is the compiler unable to
determine that foo does in fact return a List<String> and not a raw
List? Or is the compiler output simply overstating the case?