Can someone tell my why this gives a compile error? I don't see why the cast to A in the second for-loop causes strings() to return a general List of Objects.
import java.util.ArrayList;
import java.util.List;
public class E {
public static void main(String[] args) {
for (String s : new D().strings()) {
System.out.println("s = " + s);
}
for (String s : ((A) new D()).strings()) {
System.out.println("s = " + s);
}
}
static class D extends A<C> {
}
static abstract class A<T extends B> {
List<String> strings() {
return new ArrayList<String>() {{
add("Foo");
add("Bar!");
}};
}
}
static class B {
}
static class C extends B {
}
}
Is this a Generics quirk?
Thanks, Kristian