Hi. This code not compiles, because of 'A' expression. It's interesting thing: in A expression expected
List<Foo>
generic type, but got List<anonymous Foo>
(according compiler). Is it a jdk bug or feature?
interface Foo{ void doFoo(); }
public class GenericsTest {
public static<V> List<V> bar(V v){ return new ArrayList<V>();}
public static void main(String[] args) {
List<Foo> f = bar(new Foo(){ //A
public void doFoo() { }
}); //don't compiles
Foo fooImpl = new Foo(){
public void doFoo() { }
};
List<Foo> f2 = bar(fooImpl); //compiles
}
}