You do not need to do something special to deal equals
and hashcode
for Class. The current behaviour (inherited from Object
) is semantically correct. (If Eclipse is warning you otherwise, ignore it. The warnings are incorrect.)
Isn't it possible that I get two different instances of Class representing the same class? Object just uses == on them afaik. Perhaps with two classloaders or whatever, I'm not that familiar with this reflection magic.
Yes it is possible.
But in that case, they are in fact different classes from the perspective of the Java type system. (See JLS 4.3.4 for details.) And hence, you should be treating them as not equal.