get method of a class which i only have string to

Solutions on MaxInterview for get method of a class which i only have string to by the best coders in the world

showing results for - "get method of a class which i only have string to"
Alexander
08 Mar 2018
1String className = "my.class.name"; //Class name
2
3Object classObj = null;
4try {
5  classObj = Class.forName(className);
6} catch (ClassNotFoundException e) {
7  e.printStackTrace();
8}
9
10Method classMethod = null;
11try {
12  classMethod = classObj.getClass().getMethod("method", param1.class, param2.class, ..);
13} catch (SecurityException | NoSuchMethodException e) {
14  e.printStackTrace();
15}
16
17try {
18  classMethod.invoke(classObj, arg1, args2, ..);
19} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException) {
20  e.printStackTrace();
21}
22