Say I create one object and add it to my ArrayList
. If I then create another object with exactly the same constructor input, will the contains()
me
I think that right implementations should be
public class Thing
{
public int value;
public Thing (int x)
{
this.value = x;
}
@Override
public boolean equals(Object object)
{
boolean sameSame = false;
if (object != null && object instanceof Thing)
{
sameSame = this.value == ((Thing) object).value;
}
return sameSame;
}
}