I am making a method .equals
replacing the equals
method used. It accepts a object. I want it to check if that object equals the class that runs the .equals
class.
I know I want to compare all the private methods I have to that object.
Is there a way to do this without making another private class to get the private variables from the object? How do I do this to compare equality not identity? I am stuck on this. Do i have to use ==
to compare?
Also looking online i see others use recursion. If this is the way i have to do it can you show and explain it to me?
so an example i have
public boolean equals(Object o)
{
this is in a class we will call bobtheBuilder (first thing to pop in my head) I want to check if the object o is equal to the class. bobTheBuilder has private object array and a private int. I assume I want to check if the array and int of this class equal the array and int of the object. First I know i need to check if it equals null so
private _arrayObject[];
private _integerBob;
public boolean equals(Object o)
{
boolean result = true;
if (o == null)
result = false
bobTheBuilder compared = (bobTheBuilder) o;
if(compared.getArray != _arrayObject[] || compared.getInt != _integerBob)
result == false
return result
}
I know that equal checks for equality not identity so I assume this is wrong. How would I do this