Advertisement
themoosemind

Main.java

Jan 2nd, 2013
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. // I have:
  2. // Fruit.java: public class Fruit { }
  3. // Apple.java: public class Apple extends Fruit { }
  4.  
  5. // Main.java:
  6. import java.util.LinkedList;
  7. import java.util.List;
  8.  
  9. public class Main {
  10.     public static void main(String[] args) {
  11.         List<? extends Fruit> myFruits = new LinkedList<Fruit>();
  12.         List<? extends Fruit> myApples = new LinkedList<Apple>();
  13.  
  14.         myFruits.add(new Fruit());
  15.         myApples.add(new Fruit());
  16.         myFruits.add(new Apple());
  17.         myApples.add(new Apple());
  18.     /* All four give:
  19.     The method add(capture#1-of ? extends Fruit) in the type
  20.     List<capture#1-of ? extends Fruit>
  21.     is not applicable for the arguments (Fruit)
  22.     */
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement