public class Name { private String firstName; private String lastName; public Name(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } public int hashCode(){ return this.firstName.hashCode(); } public boolean equals(Object obj) { if (obj instanceof Name) { Name name = (Name) obj; return name.firstName.equals(this.firstName) && name.lastName.equals(this.lastName); } return super.equals(obj); } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } }
java hashcode写法
最新推荐文章于 2024-08-18 21:36:31 发布