Answers for "f one class is associated with another, then object of one class..........invoke the methods of the corresponding object of the other class"

1

get method of a class which I only have string to

String className = "my.class.name"; //Class name

Object classObj = null;
try {
  classObj = Class.forName(className);
} catch (ClassNotFoundException e) {
  e.printStackTrace();
}

Method classMethod = null;
try {
  classMethod = classObj.getClass().getMethod("method", param1.class, param2.class, ..);
} catch (SecurityException | NoSuchMethodException e) {
  e.printStackTrace();
}

try {
  classMethod.invoke(classObj, arg1, args2, ..);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException) {
  e.printStackTrace();
}
Posted by: Guest on February-24-2020

Code answers related to "f one class is associated with another, then object of one class..........invoke the methods of the corresponding object of the other class"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language