Hi guys,
I have a question that i would like some feedback on. Take a look at the following code fragments:
Example A:
public boolean equals(Object obj) {
if(this == obj)
return true;
// 1st conditional check
if(obj == null) || (obj.getClass() != this.getClass()))
return false;
Example B:
public boolean equals(Object obj) {
if(this == obj)
return true;
// 2nd conditional check
if(!(obj instanceof
Test)) return false;
My question is wouldn't the 1st conditional check be best to use in case the argument is a subclass of the superclass? It is my understanding that the 'instanceof' operator wouldn't return false.
Thanks in advance......
Also, to the moderators.....i wasn't sure which forum this question would be best served in, so forgive me if I broke any rules.