Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. HashMap<String, ?> hash1;
  2.  
  3. HashMap<String, Object> hash2;
  4.  
  5. public void foobar(Map<String, Object> ms) {
  6. ...
  7. }
  8.  
  9. public void foobar(Map<String, ?> ms) {
  10. ...
  11. }
  12.  
  13. public void foobar(List<? extends InputStream> ms) {
  14. ...
  15. }
  16.  
  17. HashMap<String, ?> hash1;
  18.  
  19. HashMap<String, ? extends Object> hash1;
  20.  
  21. int test1(List<?> l) {
  22. return l.size();
  23. }
  24.  
  25. int test2(List<Object> l) {
  26. return l.size();
  27. }
  28.  
  29. List<?> l1 = Lists.newArrayList();
  30. List<Object> l2 = Lists.newArrayList();
  31. test1(l1); // compiles because any list will work
  32. test1(l2); // compiles because any list will work
  33. test2(l1); // fails because a ? might not be an Object
  34. test2(l2); // compiled because Object matches Object
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement