Are Java Class objects unique / singletons? [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-20 02:05:19

问题


are Class-objects guaranteed to be unique in the JVM, are they Singletons? i.e. will

getClass() == getClass()

always hold true and is

a == b

true if and only if

a.equals(b)

where a and b are of type Class<?>?


回答1:


You can have one singleton and/or class per class loader.

a.equals(b) is required to be true if a == b (except if a is null)



来源:https://stackoverflow.com/questions/8629234/are-java-class-objects-unique-singletons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!