Answer the question
In order to leave comments, you need to log in
.class/getClass()/Class.forName() in Java. How does it work?
I read that Class.forName() in java is needed to load a class into memory (including initialization of static blocks). Now it became interesting to me, if I use the .class literal in the code, will the class also be loaded into memory? If so, then what is the difference between Class.forName() and .class/.getClass() if they all give us a reference to an object of type Class that stores information about the class?
Answer the question
In order to leave comments, you need to log in
The difference is that it Class.forName()
can, by name, load a class that is not known at compile time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question