My question is why do we use Reflection in JAVA?
Suppose I have to create an object of class. Then I may use the simple code as follows:
PersonClass pc = new PersonClass();
Where PersonClass is the class whose object I want to create. It's so simple.
Then why we will use the following code snippet using Reflection:
Class cls = Class.forName("PersonClass");
PersonClass obj = (PersonClass) cls.newInstance();
What is the advantage of it?
And also tell me the other advantages of Reflection in JAVA.
Aucun commentaire:
Enregistrer un commentaire