I wish to understand if both Class.forName("ClassName") and ClassObject.getClass
return runtime instance of the class. Then why on comparing the resulting Class object obtained from the two fetches us a Boolean false(if we compare using == or equals).
I also want to know what is the exact use of .class method called on the class name.I have read that it is determined at compile time etc but to what purpose. Won't Class.forName("ClassName") suffice??
Thanks
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Class.forName
loads and initializes the class.obj.getClass()
returns the class object loaded into permgen. If the class is loaded by the same classloader==
has to return true. When you are seefalse
for == comparison it means that they are loaded by different classloaders.Yes, they are the same - and they return the exact same object.
Example:
Will yield:
Note that the last is yielding
false
because - though the static type is the same, the dynamic type ofB
is NOTA
, and thusgetClass()
returnsB
, which is the dynamic class object ofb
.