Hi,
When doing some not really fancy things with Java, I came over an error with generics that I was not able to understand why it doesn't work. The code is:
package test;
import java.util.*;
public class TestClass {
public static class A extends C{}
public static class B extends C{}
public static class C{}
public static class D<T>{}
public static class E<T>{}
public static void main(String args[]){
E<D<? extends C>> a = new E<D<A>>();
E<D<? extends Object>> b = new E<D<? extends C>>();
E<D<? extends A>> c = new E<D<A>>();
E<D<? super A>> d = new E<D<A>>();
D<? extends C> e = new D<A>();
D<? extends A> f = new D<A>();
D<? extends A> g = new D<A>();
}
}
The error I get when compiling is:
test/TestClass.java:11: incompatible types found : test.TestClass.E> required: test.TestClass.E> E> a = new E>(); ^ test/TestClass.java:12: incompatible types found : test.TestClass.E> required: test.TestClass.E> E> b = new E>(); ^ test/TestClass.java:13: incompatible types found : test.TestClass.E> required: test.TestClass.E> E> c = new E>(); ^ test/TestClass.java:14: incompatible types found : test.TestClass.E> required: test.TestClass.E> E> d = new E>(); ^ 4 errors
If E<D<? extends C>>
is found, that should surely match E<D<? extends Object>>
, right? Or have I missed something?