diff --git a/value/src/main/java/com/google/auto/value/processor/autoannotation.vm b/value/src/main/java/com/google/auto/value/processor/autoannotation.vm index 5cdad62948..f1e62729aa 100644 --- a/value/src/main/java/com/google/auto/value/processor/autoannotation.vm +++ b/value/src/main/java/com/google/auto/value/processor/autoannotation.vm @@ -214,8 +214,16 @@ final class $className implements $annotationName, `java.io.Serializable` { @`java.lang.Override` public boolean equals($equalsParameterType o) { - if (o == this) { - return true; + int objectPropertyCount = 0; + for ($m in $members) { + if (!$m.kind.primitive) { + objectPropertyCount++; + } + } + + if (objectPropertyCount > 1) { + if (o == this) { + return true; } if (o instanceof $annotationName) { diff --git a/value/src/main/java/com/google/auto/value/processor/autovalue.vm b/value/src/main/java/com/google/auto/value/processor/autovalue.vm index ec0910c2a0..d96cf5d202 100644 --- a/value/src/main/java/com/google/auto/value/processor/autovalue.vm +++ b/value/src/main/java/com/google/auto/value/processor/autovalue.vm @@ -127,8 +127,16 @@ ${modifiers}class $subclass$formalTypes extends $origClass$actualTypes { @`java.lang.Override` public boolean equals($equalsParameterType o) { - if (o == this) { - return true; + int objectPropertyCount = 0; + for ($m in $members) { + if (!$m.kind.primitive) { + objectPropertyCount++; + } + } + + if (objectPropertyCount > 1) { + if (o == this) { + return true; } if (o instanceof $origClass) { diff --git a/value/userguide/generated-builder-example.md b/value/userguide/generated-builder-example.md index 70301c836f..e8a8cb50c0 100644 --- a/value/userguide/generated-builder-example.md +++ b/value/userguide/generated-builder-example.md @@ -39,8 +39,16 @@ final class AutoValue_Animal extends Animal { @Override public boolean equals(Object o) { - if (o == this) { - return true; + int objectPropertyCount = 0; + for ($m in $members) { + if (!$m.kind.primitive) { + objectPropertyCount++; + } + } + + if (objectPropertyCount > 1) { + if (o == this) { + return true; } if (o instanceof Animal) { Animal that = (Animal) o; diff --git a/value/userguide/generated-example.md b/value/userguide/generated-example.md index c514d52910..37a933b2d8 100644 --- a/value/userguide/generated-example.md +++ b/value/userguide/generated-example.md @@ -39,8 +39,16 @@ final class AutoValue_Animal extends Animal { @Override public boolean equals(Object o) { - if (o == this) { - return true; + int objectPropertyCount = 0; + for ($m in $members) { + if (!$m.kind.primitive) { + objectPropertyCount++; + } + } + + if (objectPropertyCount > 1) { + if (o == this) { + return true; } if (o instanceof Animal) { Animal that = (Animal) o;