I'm trying to implement the equals method in my class..
notice: the '_data' property is an double[][] array im trying to compare between the two objects.
anyway it compiles and everything but i always get a false answer and this can't be because both arrays are same :o
am i doing something wrong? is there any other easy way? (only with using equals from object class!!)
My code (JAVA):
public boolean equals(Object obj) {
if (!(obj instanceof MyClass)) {
return false;
}
MyClass myObj = (MyClass) obj;
return this._data.equals(myObj._data);
}
java.util.Arrays.deepEquals()?MyClass mc1 = new MyClass(); MyClass mc2 = mc1; boolean toCheck = mc1.equals(mc2);Does toCheck == true?equalsit is the same as using==, that is, only comparing if they are the same instance (the same reference), not if they have the same contents. Test it:int[] a = { 1 }; int[] b = { 1 }; System.out.println(a.equals(b));