Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- class Foo {
- public static class A {}
- public static class B extends A {}
- public static class C extends A {}
- public static class D extends A {}
- public static class E extends B {}
- public static class F extends B {}
- public static void main(String[] args) {
- ArrayList<? extends A> a = new ArrayList<B>();
- System.out.println(a.getClass().getName());
- a.add(new F());
- a.add(new B());
- /*
- Foo.java:16: cannot find symbol
- symbol : method add(Foo.F)
- location: class java.util.ArrayList<capture#613 of ? extends Foo.A>
- a.add(new F());
- ^
- Foo.java:17: cannot find symbol
- symbol : method add(Foo.B)
- location: class java.util.ArrayList<capture#555 of ? extends Foo.A>
- a.add(new B());
- ^
- */
- System.out.println(a.size());
- return;
- }
- }
Add Comment
Please, Sign In to add comment