Use pattern matching instead of type casting.

Closes #2754
This commit is contained in:
Junghoon Ban
2023-10-23 13:29:56 +09:00
committed by Mark Paluch
parent f28bf61142
commit 85e9ae50ff
36 changed files with 140 additions and 176 deletions

View File

@@ -91,18 +91,17 @@ public class Address implements Serializable {
return true;
if (obj == null)
return false;
if (!(obj instanceof Address))
if (!(obj instanceof Address that))
return false;
Address other = (Address) obj;
if (number == null) {
if (other.number != null)
if (that.number != null)
return false;
} else if (!number.equals(other.number))
} else if (!number.equals(that.number))
return false;
if (street == null) {
if (other.street != null)
if (that.street != null)
return false;
} else if (!street.equals(other.street))
} else if (!street.equals(that.street))
return false;
return true;
}

View File

@@ -96,28 +96,27 @@ public class Person implements Serializable {
return true;
if (obj == null)
return false;
if (!(obj instanceof Person))
if (!(obj instanceof Person that))
return false;
Person other = (Person) obj;
if (address == null) {
if (other.address != null)
if (that.address != null)
return false;
} else if (!address.equals(other.address))
} else if (!address.equals(that.address))
return false;
if (age == null) {
if (other.age != null)
if (that.age != null)
return false;
} else if (!age.equals(other.age))
} else if (!age.equals(that.age))
return false;
if (firstName == null) {
if (other.firstName != null)
if (that.firstName != null)
return false;
} else if (!firstName.equals(other.firstName))
} else if (!firstName.equals(that.firstName))
return false;
if (lastName == null) {
if (other.lastName != null)
if (that.lastName != null)
return false;
} else if (!lastName.equals(other.lastName))
} else if (!lastName.equals(that.lastName))
return false;
return true;
}