check instanceof Movie

This commit is contained in:
Ulisses Lima 2023-06-07 12:20:25 -03:00
parent b0e5cff217
commit 80e0f8b2e6

View File

@ -4,20 +4,24 @@ import java.util.Objects;
record Movie(String name, Integer yearOfRelease, String distributor) { record Movie(String name, Integer yearOfRelease, String distributor) {
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (this == other) { if (this == other) {
return true; return true;
} }
if (other == null) { if (other == null) {
return false; return false;
} }
if (!(other instanceof Movie)) {
return false;
}
Movie movie = (Movie) other; Movie movie = (Movie) other;
if (movie.name.equals(this.name) && movie.yearOfRelease.equals(this.yearOfRelease)) { if (movie.name.equals(this.name) && movie.yearOfRelease.equals(this.yearOfRelease)) {
return true; return true;
} }
return false; return false;
} }
@Override @Override
public int hashCode() { public int hashCode() {