filmov
tv
27. Java Reflections - Loading classes, constructors and methods at run time
![preview_player](https://i.ytimg.com/vi/5jbq18YnV0c/maxresdefault.jpg)
Показать описание
In this video we will look at Java Reflections which is used to load classes, constructors and methods at run time.
Java Reflections – Loading Classes, Constructors and Methods at Run Time:
Java reflections package is used if we want to load any class, it’s constructor or methods at run time. In this one we only see what is needed for our selenium tutorials.
Here we created a package “actions” and a class under it called HomePage. We have created two static variables and a constructor to initialize those variables. We have also created four methods as well.
We have created another package “drivers” and class under it “ContactActions”. In this class we don’t create any object for HomePage class but we dynamically access this class and it’s constructor and methods at run time.
Yu can get all the methods of the class by using getDeclaredMethods() which returns an array of public methods the class has. So we save all these in Method[].
To invoke any method first we have to load the method. This we do it with
Next before invoking the method, we need to load the constructor. We use getConstructor() method and the variable types the constructor use.
Java Reflections – Loading Classes, Constructors and Methods at Run Time:
Java reflections package is used if we want to load any class, it’s constructor or methods at run time. In this one we only see what is needed for our selenium tutorials.
Here we created a package “actions” and a class under it called HomePage. We have created two static variables and a constructor to initialize those variables. We have also created four methods as well.
We have created another package “drivers” and class under it “ContactActions”. In this class we don’t create any object for HomePage class but we dynamically access this class and it’s constructor and methods at run time.
Yu can get all the methods of the class by using getDeclaredMethods() which returns an array of public methods the class has. So we save all these in Method[].
To invoke any method first we have to load the method. This we do it with
Next before invoking the method, we need to load the constructor. We use getConstructor() method and the variable types the constructor use.