Java: use deepEquals() / deepHashCode() for multi-dimensional arrays (IDEA-199543)

when generating equals() and hashCode() methods using the "java.util.Objects.equals() and hash() (java 7+)" template

GitOrigin-RevId: a863b875fa482542bbb9b2efc5e61cfa2bfb787d
This commit is contained in:
Bas Leijdekkers
2023-11-19 22:07:30 +01:00
committed by intellij-monorepo-bot
parent f8773787b2
commit caab7e4bf9
9 changed files with 79 additions and 104 deletions

View File

@@ -1,4 +1,5 @@
import java.util.Arrays;
import java.util.Objects;
class I {
public int hashCode() {
@@ -18,13 +19,11 @@ class A extends I {
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
final A a = (A) o;
return Arrays.equals(a1, a.a1);
return Objects.deepEquals(a1, a.a1);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + Arrays.hashCode(a1);
return result;
return Objects.hash(super.hashCode(), Arrays.hashCode(a1));
}
}