Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public class Person {
  2. public final String name;
  3. public final int age;
  4. public final String city;
  5.  
  6. public Person(String name, int age, String city) {
  7. this.name = name;
  8. this.age = age;
  9. this.city = city;
  10. }
  11.  
  12. @Override
  13. public boolean equals(Object o) {
  14. if (this == o) return true;
  15. if (o == null || getClass() != o.getClass()) return false;
  16.  
  17. Person person = (Person) o;
  18.  
  19. if (age != person.age) return false;
  20. if (name != null ? !name.equals(person.name) : person.name != null) return false;
  21. return city != null ? city.equals(person.city) : person.city == null;
  22. }
  23.  
  24. @Override
  25. public int hashCode() {
  26. int result = name != null ? name.hashCode() : 0;
  27. result = 31 * result + age;
  28. result = 31 * result + (city != null ? city.hashCode() : 0);
  29. return result;
  30. }
  31.  
  32. @Override
  33. public String toString() {
  34. return "Person{" +
  35. "name='" + name + '\'' +
  36. ", age=" + age +
  37. ", city='" + city + '\'' +
  38. '}';
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement