Are null objects equal?
This is really more a philosophical question than a programming question, but one that has been sitting in the back of my mind for a couple of weeks.
If two objects are null, are they equal to each other[0]?
I can see three possible answers:
(a) They're neither equal nor unequal.. because two null objects cannot be compared in the Java world using the good old Object.equals() -- but of course that's only because you cannot call equals() on a null object, so that in itself is not a good enough reason.
(b) They're unequal because we cannot determine any function of equality (usually when we equate objects it's because of some attribute(s)) -- this one breaks down as well, since lack of attributes can be treated as an attribute itself.
(c) They're equal because they lack attributes and all things considered equal, they are identical in the fact that they're null and since Java considers two empty strings as equal (somehow that one is easier to swallow) then it falls within the Java view of the world.
I may be the only person in the world who has a problem just coming up with a simple answer to this one[1], but my gut feeling says it's (c) with a little bit of a mixed in: If the objects are of the same type then they're equal, otherwise it's undeterminable. Which means, two null strings are equal, but a null String object and a null String[] object are not[2].
[0] By equal I mean the Java view of equal, meaning: they're either the same object or their attributes match based on some object-specific function.
[1] Feel free to think me an idiot for even wondering about this.
[2] Of course, there's no way you can tell what an object isn't when it's null.. but it's the intentions that count and this is purely academic anyway.