Override equals and toString methods
//Rewrute equals
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj instanceof People) {
People p = (People)obj;
if (p.name.equals(this.name) && p.age == this.age && p.sex == this.sex) {
return true;
}
}
return false;
}
//Rewrute tostring
public String toString() {
return name+":"+age+":"+sex;
}
Read More:
- “Method does not override method from its superclass”
- The differences between the equals method in the string class and the equals method in the object class
- JavaScript summary: the difference between typeof and instanceof, and Object.prototype.toString() method
- @Solution to override error
- The solution of multiple markers at this line @ override
- Difference between isempty method and isblank method in stringutils
- Error: no override found for ‘vtkPolyDataMapper’.
- Solution to error reporting in Java @ override
- Error: no override found for ‘vtkRayCastImageDisplayHelper’.
- [PCL + QT + vs] no override found for ‘vtkrenderwindow’ error resolution
- org.hibernate.MappingException: invalid override definition
- The solution to the error of “no override found for * *” in the use of VTK
- Solve the problem that power view in Excel prompts activate method of oleobject class failed or activate method like oleobject is invalid
- On the intern () method of string class in Java
- Python’s direct method for solving linear equations (5) — square root method for solving linear equations
- Generating equals/hashCode implementation but without a call to superclass
- Java compareto() method
- Error analysis of queryformap method of jdbctemplate
- HBase checkandput() method
- invalid method declaration