P
plewto
In the following code Node is an abstract class and both Gate and
Monitor are extensions of Node. a and b are distinct objects yet
a.equals(b) is returning true.
public class Foo {
public static void main(String[] argv){
Node a = new Gate();
Monitor b = new Monitor();
System.out.println(a.equals(b)); // --> prints 'true'
}
}
The underlying production code is a bit complex to include here. My
understanding is that equals is true if, and only if, a and b are
exactly the same object. Here they are not even the same class.
I did do a test stripped down to the bare essence:
public class Foo {
public static void main(String[] argv){
Foo a = new Bar();
Foo b = new Bar();
System.out.println(a.equals(b)); // --> prints 'false'
}
}
class Bar extends Foo {}
In this case the results are as I expected, a.equals(b) --> false
What could be going on here?
java version 1.7.0_06 on 64-bit Fedora 17
Monitor are extensions of Node. a and b are distinct objects yet
a.equals(b) is returning true.
public class Foo {
public static void main(String[] argv){
Node a = new Gate();
Monitor b = new Monitor();
System.out.println(a.equals(b)); // --> prints 'true'
}
}
The underlying production code is a bit complex to include here. My
understanding is that equals is true if, and only if, a and b are
exactly the same object. Here they are not even the same class.
I did do a test stripped down to the bare essence:
public class Foo {
public static void main(String[] argv){
Foo a = new Bar();
Foo b = new Bar();
System.out.println(a.equals(b)); // --> prints 'false'
}
}
class Bar extends Foo {}
In this case the results are as I expected, a.equals(b) --> false
What could be going on here?
java version 1.7.0_06 on 64-bit Fedora 17