Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // I have:
- // Fruit.java: public class Fruit { }
- // Apple.java: public class Apple extends Fruit { }
- // Main.java:
- import java.util.LinkedList;
- import java.util.List;
- public class Main {
- public static void main(String[] args) {
- List<? extends Fruit> myFruits = new LinkedList<Fruit>();
- List<? extends Fruit> myApples = new LinkedList<Apple>();
- myFruits.add(new Fruit());
- myApples.add(new Fruit());
- myFruits.add(new Apple());
- myApples.add(new Apple());
- /* All four give:
- The method add(capture#1-of ? extends Fruit) in the type
- List<capture#1-of ? extends Fruit>
- is not applicable for the arguments (Fruit)
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement