public static void Main (string[] args) {//Object <-Fruit <-Apple <-redapple System.out.pri Ntln (Apple.class.isAssignableFrom (Fruit.class)); System.out.println (Fruit.class.isAssignableFrom (Fruit.class)); System.out.println (Fruit.class.isAssignableFrom (Apple.class)); Apple is fruit subclass//covariant list<apple> apples = new arraylist<apple> (); list<? Extends fruit> listfruits = apples;//listfruits.add (new Apple ());//Listfruits.add (New Redapple ());// Listfruits.add (New Fruit ()); ERROR: cannot be used for one? Any value is written in the extends data structure. Fruit f = listfruits.get (0); Inverter list<fruit> fruits = new arraylist<fruit> (); list<? Super Apple> List2 = fruits;//list2.add (new Fruit ()); ERROR List2.add (New Apple ()); List2.add (New Redapple ());//Fruit F = list2.get (0); ERROR/* Access principle and pecs rule summary? Extends and the? SuperWildcard character, we can draw the following conclusions: If you want to get data from a data type, use the? Extends wildcard if you want to write an object into a data structure, use the? Super Wildcard If you want to save and take it, don't use wildcard characters. This is the principle of access that Maurice Naftalin in his book Java Generics and collections, and the Joshua Rule Bloch effective in his book Pecs java. Bloch reminded that this pecs refers to "Producer Extends, Consumer Super", this is more easy to remember and use. * */ }
Http://www.cnblogs.com/softidea/p/4106659.html
Java covariant inversion, PECS