Over a million developers have joined DZone.

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;

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}