Comparing Object with null
From: Asad Khan (uoft_cstutor_at_yahoo.com)
Date: 10/31/03
- Next message: Adam: "Re: Comparing Object with null"
- Previous message: ak: "Re: java code to fake form POST?"
- Next in thread: Adam: "Re: Comparing Object with null"
- Reply: Adam: "Re: Comparing Object with null"
- Reply: xarax: "Re: Comparing Object with null"
- Reply: Roedy Green: "Re: Comparing Object with null"
- Reply: Roedy Green: "Re: Comparing Object with null"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 31 Oct 2003 16:21:14 GMT
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.
- Next message: Adam: "Re: Comparing Object with null"
- Previous message: ak: "Re: java code to fake form POST?"
- Next in thread: Adam: "Re: Comparing Object with null"
- Reply: Adam: "Re: Comparing Object with null"
- Reply: xarax: "Re: Comparing Object with null"
- Reply: Roedy Green: "Re: Comparing Object with null"
- Reply: Roedy Green: "Re: Comparing Object with null"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|