diff options
author | Merrg1n <[email protected]> | 2022-08-13 22:36:35 +0800 |
---|---|---|
committer | Merrg1n <[email protected]> | 2022-08-14 01:42:37 +0800 |
commit | 94f092015a05d0179e307468c717ad391e455742 (patch) | |
tree | 1e90e0462e8bc2a6d4ae4131808b655089db72a9 /src/main/java/com/keuin/ohmyvanillamc/ReflectionUtils.java | |
parent | 323226a7956b2dc1d56c56e63bc9354e2b8bd244 (diff) |
carpet ext
Diffstat (limited to 'src/main/java/com/keuin/ohmyvanillamc/ReflectionUtils.java')
-rw-r--r-- | src/main/java/com/keuin/ohmyvanillamc/ReflectionUtils.java | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/src/main/java/com/keuin/ohmyvanillamc/ReflectionUtils.java b/src/main/java/com/keuin/ohmyvanillamc/ReflectionUtils.java deleted file mode 100644 index a87632e..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/ReflectionUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.keuin.ohmyvanillamc; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; - -/** - * @Author 落叶飞翔的蜗牛 Keuin - * @Date 2018/3/10 - * @Description 常用反射函数 - */ -public final class ReflectionUtils { - - /** - * 获取私有成员变量的值 - */ - public static Object getPrivateField(Object instance, String filedName) throws NoSuchFieldException, IllegalAccessException { - Field field = instance.getClass().getDeclaredField(filedName); - field.setAccessible(true); - return field.get(instance); - } - - /** - * 设置私有成员的值 - */ - public static void setPrivateField(Object instance, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException { - Field field = instance.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - field.set(instance, value); - } - - /** - * 访问私有方法 - */ - public static Object invokePrivateMethod(Object instance, String methodName, Class[] classes, Object... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method method = instance.getClass().getDeclaredMethod(methodName, classes); - method.setAccessible(true); - return method.invoke(instance, args); - } - - /** - * 获取所有成员变量的名字 - * - * @param o 要获取成员变量的对象实例 - * @return 所有成员变量名字数组 - */ - public static String[] getFieldName(Object o) { - return Arrays.stream(o.getClass().getDeclaredFields()).map(Field::getName).toArray(String[]::new); - } -}
\ No newline at end of file |