Guest User

Untitled

a guest
Aug 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. class Foo {
  4.  
  5. public static class A {}
  6. public static class B extends A {}
  7. public static class C extends A {}
  8. public static class D extends A {}
  9. public static class E extends B {}
  10. public static class F extends B {}
  11.  
  12. public static void main(String[] args) {
  13. ArrayList<? extends A> a = new ArrayList<B>();
  14.  
  15. System.out.println(a.getClass().getName());
  16. a.add(new F());
  17. a.add(new B());
  18. /*
  19. Foo.java:16: cannot find symbol
  20. symbol : method add(Foo.F)
  21. location: class java.util.ArrayList<capture#613 of ? extends Foo.A>
  22. a.add(new F());
  23. ^
  24. Foo.java:17: cannot find symbol
  25. symbol : method add(Foo.B)
  26. location: class java.util.ArrayList<capture#555 of ? extends Foo.A>
  27. a.add(new B());
  28. ^
  29. */
  30.  
  31. System.out.println(a.size());
  32.  
  33. return;
  34. }
  35.  
  36. }
Add Comment
Please, Sign In to add comment