what is class.forname() and how it will be useful ?
Answer Posted / pradip
class.forname() is used to create an instance of a class on
the basis of the name in string format instead of doing new
Class. One of its use is in cases where you have some
generic (common) logic to call methods of some classes just
on the basis of the names of the class and the method. The
example of reflection shown below uses the logic.
Eg:
performAction(String className, String methodName) {
Class class = Class.forName(className);
MethodUtils.invokeMethod(class.newInstance, methodName,
null);
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
How do you declare an array in java?
How do you compare values in java?
What is an association?
What is scope of a variable?
What is anagram in java?
Which is better ascii or unicode?
How do you compare objects in java?
What is the difference between synchronized and synchronized block?
What does function identity () do?
What is the default size of set in java?
When do we need to use internal iteration? When do we need to use external iteration?
What are methods in java?
What is a function argument in java?
Should you use singleton pattern?
What is a double?