No generic type checking at all for raw types?

  • Thread starter Christopher Benson-Manica
  • Start date
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top