public static void main(String[] args) {
}
public boolean equals (Object o){
System.out.println("This is my equals");
return true;
}
TestClass s1 = new TestClass();
TestClass s2 = new TestClass();
Object o = s1;
System.out.println(o.equals(s2)); //gives false. Shouldn't this give
true going by your answer above
System.out.println(o== s2); // gives false as well
Your comments are obviously describing the behavior of code that's
different from what you've actually posted. After all, the class you
posted does nothing at all, and the rest of the code you posted is out of
context. There's no way to get the code you posted to do what you say it
does.
Without a concise-but-complete code example that reliably demonstrates the
behavior you're describing, it's not possible to answer definitively.
But, here's an example that actually _does_ what you obviously intended
your example to do, but which behaves in exactly the way that Joshua
explained:
public class TestOverrideEquals
{
public static void main(String[] args)
{
Object o1 = new TestOverrideEquals();
Object o2 = new TestOverrideEquals();
System.out.println(o1.equals(o2));
System.out.println(o1 == o2);
}
public boolean equals(Object o)
{
return true;
}
}
This prints "true" and then "false" to the console.
If you have some code that is behaving contrary to your expectations, you
need to post that code _exactly_. Just copy-and-paste it from your actual
code into your newsgroup post.
Pete