Why does the following compile? I get a warning telling me that
getTest() returns a raw type so getTestIntegers() is erased
But I don't understand why, getTestIntegers()
is not generic. I would have expected List<String> tester = Test.getTest().getTestIntegers()
to produce a compile error
public class Scratchpad {
public static void main(String[] args) {
new Scratchpad().run();
}
private void run() {
List<String> tester = Test.getTest().getTestIntegers();
}
private static class Test<T> {
public static Test getTest() {
return new Test();
}
public List<Integer> getTestIntegers() {
return Collections.singletonList(1);
}
}
}