Java: Comparing a class with another within that class using a my own .equals

Posted by user1670252 on Stack Overflow See other posts from Stack Overflow or by user1670252
Published on 2012-10-18T22:45:14Z Indexed on 2012/10/18 23:00 UTC
Read the original article Hit count: 198

Filed under:
|
|
|

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 he 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.

© Stack Overflow or respective owner

Related posts about java

Related posts about object