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?

Signature
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Piotr Kobzda - 10 Oct 2006 21:29 GMT
> 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?
All this is deeply discussed there:
http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.8
piotr