-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add utils for reflection and deal with IBM JDK
- Loading branch information
Showing
2 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
amoro-common/src/main/java/org/apache/amoro/utils/ReflectionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.apache.amoro.utils; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ReflectionUtils { | ||
|
||
private final static Map<String,Class> CLASS_MAP = new HashMap<>(); | ||
|
||
public static Object invoke(String className, String methodName) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { | ||
Class<?> classRef = CLASS_MAP.computeIfAbsent(className, key-> { | ||
try { | ||
return Class.forName(className); | ||
} catch (ClassNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
Method method = classRef.getDeclaredMethod(methodName); | ||
return method.invoke(null); | ||
} | ||
} |