Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. List<String> listStr = new ArrayList<>();
  2. listStr.contains(34); //warning
  3.  
  4. Given object can not contain instances of int (expected String)
  5.  
  6. List<?> listStr = new ArrayList<>();
  7.  
  8. public class FakeString {
  9. private final String value;
  10.  
  11. public FakeString(String value) {
  12. if (value == null) {
  13. throw new IllegalArgumentException();
  14. }
  15. this.value = value;
  16. }
  17.  
  18. public int hashCode() {
  19. return value.hashCode();
  20. }
  21.  
  22. public boolean equals(Object o) {
  23. return value.equals(o);
  24. }
  25. }
  26.  
  27. List<String> strings = Arrays.asList("foo", "bar", "baz");
  28. System.out.println(strings.contains(new FakeString("bar")));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement