java - Do two classes of the same class have the same hashcode and are they considered equal? -
i want create hashmap of classes (object.class). wondering whether
object.class considered equal object.class?
can there instance of object.class leads have different hashcode?
the literal object.class
return same reference within same classloader.
from section 15.8.2 of jls:
a class literal evaluates class object named type (or void) defined defining class loader of class of current instance.
note definite article ("the") in quote above - there's one class
object particular class, within same class loader.
so yes, you'll same hashcode - because you'll have 2 references same object.
Comments
Post a Comment