1 package com.tn.hashSet; 2 3 public class Person { 4 private int id; 5 private String name; 6 private String birthday; 7 public Person(int id, String name, String birthday) { 8 super(); 9 this.id = id; 10 this.name = name; 11 this.birthday=birthday; 12 } 13 public int getId() { 14 return id; 15 } 16 public void setId(int id) { 17 this.id = id; 18 } 19 public String getName() { 20 return name; 21 } 22 public void setName(String name) { 23 this.name = name; 24 } 25 public String getBirthday() { 26 return birthday; 27 } 28 public void setBirthday(String birthday) { 29 this.birthday = birthday; 30 } 31 @Override 32 public String toString() { 33 return id +"-" + name; 34 } 35 @Override 36 public int hashCode() { 37 final int prime = 31; 38 int result = 1; 39 result = prime * result + id; 40 return result; 41 } 42 @Override 43 public boolean equals(Object obj) { 44 if (this == obj) 45 return true; 46 if (obj == null) 47 return false; 48 if (getClass() != obj.getClass()) 49 return false; 50 Person other = (Person) obj; 51 if (id != other.id) 52 return false; 53 return true; 54 } 55 }
相关文章: