You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 11, 2025. It is now read-only.
sebastianchristopher edited this page Sep 13, 2019
·
2 revisions
Type casting
Whenever our applications save objects to databases, we'll need to override the equals() method, and cast its general Object argument into a more-specific type for comparison.
public class ToDo {
private int id;
private String content;
private int labelId;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ToDo toDo = (ToDo) o;
return id == toDo.id &&
labelId == toDo.labelId &&
Objects.equals(content, toDo.content);
}
@Override
public int hashCode() {
return Objects.hash(id, content, labelId);
}
That's a lot of code to have to remember each time - fortunately Injellij has a way of doing this for you: