Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Compact Equals Method

DZone's Guide to

Compact Equals Method

· ·
Free Resource

class Foo {
   private String string;
   private int i;
   [...]

   public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Foo)) return false;

        final Foo other = (Foo) o;

        if (string != null ? !string.equals(other.name) : other.name != null) return false;
        if (i != other.i) return false;
        [...]
        return true;
}
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}