Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A general solution is to wrap the array in a method that does implement <code>equals</code> (and <code>hashCode</code> and perhaps <code>compare</code>, possibly <code>toString</code> and other methods that might make sense) as you wish:</p> <pre><code>public final class IntArrayWrapper { private final IntArrayWrapper[] values; public IntArrayWrapper(int... values) { if (values == null) { throw new NullPointerException(); } this.values = values; } @Override public boolean equals(Object obj) { if (!(obj instanceof IntArrayWrapper)) { return false; } IntArrayWrapper other = (IntArrayWrapper)obj; return java.util.Arrays.equals(this.values, other.values); } @Override public int hashCode() { return java.util.Arrays.hashCode(values); } public int[] getValues() { return values; } [...] } </code></pre> <p>In this specific case, using arrays to contain certain fixed data values is poor design. Do it properly:</p> <pre><code>public final class Point { private final int x; private final int y; private final int z; public static Point of(int x, int y, int z) { return new Point(x, y, z); } private Point(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } @Override public boolean equals(Object obj) { if (!(obj instanceof Point)) { return false; } Point other = (Point)obj; return this.x == other.x &amp;&amp; this.y == other.y &amp;&amp; this.z == other.z; } @Override public int hashCode() { int hash; hash = x; hash = hash*41+y; hash = hash*41+z; return hash; } [...] } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload