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 😮
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);
}
I would override the equals method in your MyClass class.
This code considers the case you will have a two dimensional array but not a square matrix. i.e. first row with three elements, second row with 27 elements, third row with N elements…
For example, a test case: