-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Standardize #equals(Object) implementations #901
Comments
Style A addressbook-level4/src/main/java/seedu/address/commons/core/GuiSettings.java Lines 43 to 58 in c9b222c
|
Style B addressbook-level4/src/main/java/seedu/address/model/AddressBook.java Lines 107 to 112 in c9b222c
|
@Zhiyuan-Amos @yamgent @yamidark Okay, it's quite obvious by now that Style A is the winner, but there are a few details to iron out. Here's my proposal: public boolean equals(Object other) { The name if (other == this) {
return true;
} Some implementations add a // instanceof handles nulls
if (!(other instanceof Foo)) {
return false;
} Some implementations write the comment as Some implementations don't even put any comment, but I think the comment adds value (I didn't know that when I was starting out with Java :-P )Although would Foo otherFoo = (Foo) other; Some implementations call this various names ( Some implementations add a If the object in question does not have any fields, this can be replaced with just a return field1.equals(otherFoo.field1)
&& field2.equals(otherFoo.field2); The instance's own fields must come first, followed by the other object's fields. Use Any thoughts? |
I think the comment is certainty useful, since Java's design can be quite haphazard sometimes. One just can't be sure that Java won't do something funny like throwing a The rest looks good. 👍 |
Style A or Style B? Vote with 👍 now!
The text was updated successfully, but these errors were encountered: