0

I just read topics about generic wild card. "?", "extends", and "super" from SCJP 6 book. My question is related to method declaration using super and extends.

class A {
}
class B extends A {
}
class C extends B {
}
class D extends C {
}

public class Class_1 {

    public static void main(String args[]) 
    {       
         List<B> bs = new ArrayList<B>();
         List<A> as = new ArrayList<A>();
         List<C> cs = new ArrayList<C>();
         List<D> ds = new ArrayList<D>();
         Class_1 class_1 = new Class_1();
         class_1.getName3(ds);
         class_1.getName4(bs);
         class_1.getName1(cs);
         class_1.getName2(as);
    }

    public void getName3(List<? extends B> list)
    {
    }
    public void getName4(List<? super B> list)
    {
    }
    public <T extends B> void getName1(List<T> list)
    {   
    }
    public <T super B> void getName2(List<T> list)
    {       
    }
}

I am getting compilation error at class_1.getName2(as);. Why ? Error is saying

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The method getName2(List<T>) from the type Class_1 refers to the missing type T

    at com.ksh.scjp.gNc.Class_1.main(Class_1.java:26) 
KSHiTiJ
  • 1,521
  • 7
  • 31
  • 51

0 Answers0