In fact, a word is:
Super is best used as an output parameter, extends is best used as input parameter;
Take a look at the following example:
Private Class A {//} private class B extends A {//} private class C extends B {// } public void Test () {list<? super b> test = new ArrayList (); Test = new arraylist<a> (); Test = new arraylist<b> (); Test = new arraylist<c> (); Cannot accept a Class A = Test.get (0) smaller than B;//cannot get b b = test.get (0);//Cannot get c c = test.get (0);//Cannot get TES T.add (New A ());//But cannot add a class Test.add (new B ()) larger than B; Test.add (New C ()); list<? Extends b> test1 = new ArrayList (); Test1 = new arraylist<a> ()//cannot accept class test1 = new arraylist<b> () larger than B; Test1 = new arraylist<c> (); A a1 = test1.get (0); B B1 = test1.get (0); C C1 = test1.get (0);//But cannot get a class Test1.add (new A ()) smaller than B,//Cannot add Test1.add (new B ());//Cannot add test1.add (NE W C ());//Cannot add}
The following is a compilation error in Eclipse:
Specific reasons can be found in:
Http://stackoverflow.com/questions/4343202/difference-between-super-t-and-extends-t-in-java
Http://docs.oracle.com/javase/tutorial/java/generics/capture.html
The difference between super and extends in Java paradigm