Consistent equals/hashCode style (and related polishing)

This commit is contained in:
Juergen Hoeller
2023-07-19 00:35:19 +02:00
parent bbcc788f60
commit 2f33e77ab4
98 changed files with 413 additions and 835 deletions

View File

@@ -65,10 +65,8 @@ public class SerializablePerson implements Person, Serializable {
@Override
public boolean equals(@Nullable Object other) {
if (!(other instanceof SerializablePerson p)) {
return false;
}
return p.age == age && ObjectUtils.nullSafeEquals(name, p.name);
return (this == other || (other instanceof SerializablePerson that &&
ObjectUtils.nullSafeEquals(this.name, that.name) && this.age == that.age));
}
@Override

View File

@@ -466,18 +466,13 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof TestBean tb2)) {
return false;
}
return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age);
return (this == other || (other instanceof TestBean that &&
ObjectUtils.nullSafeEquals(this.name, that.name) && this.age == that.age));
}
@Override
public int hashCode() {
return this.age;
return TestBean.class.hashCode();
}
@Override