I have a class that's a multiton, so I know that given a particular key, there will never be two instances of the same class that exist. This means that, instead of:
if (someObject.equals(anotherObject))
...it's safe for me to do this:
if (someObject == anotherObject)
The class is also final
, so I know that nothing related to polymorphism could cause problems for comparison either.
IDEA dutifully informs me that it's risky to compare two instances directly and that I should use .equals()
, but I know it's not in this case. Is there some annotation I can apply to my class to instruct IDEA, and potentially other editors and more importantly other users, that a direct reference comparison for equality on instances of my class is safe?
I know I could just tell IDEA to suppress the warning, but I'd have to do it for every comparison between these two types or globally, neither of which is a good idea. Plus, it's more important that I let users of my class know it's safe, faster, and even preferred (convince me otherwise) over .equals()
.