Menu

#482 Object.equals(Object) check against class heirarchy

open
None
5
2012-10-07
2007-05-09
No

I would like to be able to identify when an Object.equals() check is likely to be nonsense.

For example:

if ("someStaticString".equals(someObject.getWhatever())
{
}

If the type returned by "someObject.getWhatever()" is not an 'instanceof' String, then this equality check is likely to be wrong. Technically one could override equals to do something funky to violate this premise, but if you're not, then this is an ugly bug.

Also, one could if desired extend this to the other relational operations in Java, such as Comparable.compareTo(Object), Comparator.compare(Object, Object), and any others I've overlooked.

Discussion


Log in to post a comment.