Guest User

Untitled

a guest
Aug 10th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. Understanding wildcards in Java generics
  2. List<String> a = new ArrayList<String>();
  3. a.add("foo");
  4.  
  5. // b is a List of anything
  6. List<?> b = a;
  7.  
  8. // retrieve the first element
  9. Object c = b.get(0);
  10. // This is legal, because we can guarantee
  11. // that the return type "?" is a subtype of Object
  12.  
  13. // Add an Integer to b.
  14. b.add(new Integer (1));
  15.  
  16. Object c = b.get(0);
  17.  
  18. public Foo findAFooThatILike(Collection<? extends Foo> foos);
  19.  
  20. public Foo findAFooThatILike(Collection<Foo> foos);
Add Comment
Please, Sign In to add comment