A
Asad Khan
public boolean equals(Object o) {
if (!(o.equals(null))) { // *
if (o instanceof foo) {
if (this.equals(o)) {
return true;
}
}
}
return false;
}
I have the above method in a class foo. When I run the following code:
f.equals(f)
where f is an object of class foo, then I get a nullpointerexception in this
method. The reason is that since f is of type foo, in line * it recursively
calls the equals method and then o becomes null, and of course I can't
dereference null.
So how can I check if an object is null or not?
Thanks.
if (!(o.equals(null))) { // *
if (o instanceof foo) {
if (this.equals(o)) {
return true;
}
}
}
return false;
}
I have the above method in a class foo. When I run the following code:
f.equals(f)
where f is an object of class foo, then I get a nullpointerexception in this
method. The reason is that since f is of type foo, in line * it recursively
calls the equals method and then o becomes null, and of course I can't
dereference null.
So how can I check if an object is null or not?
Thanks.