comparing an object with null
Date: Fri, 31 Oct 2003 16:20:47 GMT
I have the following method in a class 'foo'.
public boolean equals(Object o) {
if (!(o.equals(null))) {
// do some stuff
}
}
The problem I am having is that, if the object that is passed in is
instanceof foo, then it recursively calls the equals method, and I get a
nullpointer exception. So how can I compare if the object that is being
passed in is null or not?
Thanks.
Relevant Pages
- Re: OOP - a question about database access
... > public boolean performFooAction ... > public class MyFooAction ... > public boolean perform(Foo foo) ... > Then the client code can operate on all objects in a query as follows: ... (comp.object) - Re: comparing an object with null
... > I have the following method in a class 'foo'. ... > public boolean equals{ ... sole pointer in Java! ... (comp.lang.java) - Re: OOP - a question about database access
... public boolean performFooAction ... public class MyFooAction ... public boolean perform(Foo foo) ... IFooAction myFooAction = new MyFooAction; ... (comp.object) - Re: Newbie question: How to write a set?
... ensure only unique instances of Foo are placed in the set? ... public boolean equals{ ... public int hashCode() { ... // equals() takes into consideration ... (comp.lang.java.programmer) - Re: comparing an object with null
... > I have the following method in a class 'foo'. ... > public boolean equals{ ... So how can I compare if the object that is being ... Remember, objects are not passed, object references are passed. ... (comp.lang.java) |
|