程序包 com.sh.util
类 ReflectUtil
java.lang.Object
com.sh.util.ReflectUtil
Description: 反射工具类
Title:首亨软件 - CRM、TSS、ERP等信息化管理软件
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static ObjectcreateInstance(String className) 实例化对象static ObjectcreateInstance(String className, Class[] clazzParam, Object[] param) 创建对象static ObjectexecuteMethod(Object instance, String method) 执行方法static Object[]executeMethod(String className, String method) 执行指定的方法static ObjectexecuteMethodByParam(Object instance, String method, Class<?>[] parameterType, Object[] paramValue) 执行带参数的方法static ObjectexecuteMethodByParam(String className, String method, Class<?>[] parameterType, Object[] paramValue) 执行带参数的方法static ObjectexecuteStaticMethod(String className, String method) 执行不带参数的静态方法static ObjectexecuteStaticMethodByParam(Class<?> clazz, String method, Class<?>[] parameterType, Object[] paramValue) 执行带参数的静态方法static ObjectexecuteStaticMethodByParam(String className, String method, Class<?>[] parameterType, Object[] paramValue) 执行带参数的静态方法findAllImplementsClass(Class<?> interfaceClass) 查找指定接口的所有实现类(会在shforce-开头的JAR包及目录中查找)static ObjectgetFieldValue(Object instance, String fieldName) 设置属性值static ObjectgetStaticFieldValue(String className, String fieldName) 获取静态属性值static booleanisFieldExists(Object instance, String fieldName) 判断列是否存在static voidsetFieldValue(Object instance, String fieldName, Object fieldValue) 设置变量值static voidsetStaticFieldValue(String className, String fieldName, Object fieldValue) 设置静态变量值
-
构造器详细资料
-
ReflectUtil
public ReflectUtil()
-
-
方法详细资料
-
executeStaticMethod
执行不带参数的静态方法- 参数:
className- 类详细路径,需要指定详细包路径method- 执行方法名- 返回:
- 根据静态方法返回值确定
- 抛出:
ReflectException- 执行异常
-
executeStaticMethodByParam
public static Object executeStaticMethodByParam(String className, String method, Class<?>[] parameterType, Object[] paramValue) throws ReflectException 执行带参数的静态方法- 参数:
className- 类名method- 执行方法名parameterType- 参数类型paramValue- 参数值- 返回:
- 根据静态方法返回值确定
- 抛出:
ReflectException- ReflectException
-
executeStaticMethodByParam
public static Object executeStaticMethodByParam(Class<?> clazz, String method, Class<?>[] parameterType, Object[] paramValue) throws ReflectException 执行带参数的静态方法- 参数:
clazz- 类名method- 执行方法名parameterType- 参数类型paramValue- 参数值- 返回:
- 根据静态方法返回值确定
- 抛出:
ReflectException- ReflectException
-
getStaticFieldValue
public static Object getStaticFieldValue(String className, String fieldName) throws ReflectException 获取静态属性值- 参数:
className- 类名fieldName- 属性名称- 返回:
- 根据属性类型确定
- 抛出:
ReflectException- ReflectException
-
setStaticFieldValue
public static void setStaticFieldValue(String className, String fieldName, Object fieldValue) throws ReflectException 设置静态变量值- 参数:
className- 类名fieldName- 属性名称fieldValue- 属性值- 抛出:
ReflectException- ReflectException
-
createInstance
实例化对象- 参数:
className- 类名- 返回:
- 实例化对象,创建失败时返回:null
- 抛出:
ReflectException- ReflectException
-
createInstance
public static Object createInstance(String className, Class[] clazzParam, Object[] param) throws ReflectException 创建对象- 参数:
className- StringclazzParam- Class[]param- Object[]- 返回:
- Object
- 抛出:
ReflectException- ReflectException
-
executeMethod
执行指定的方法- 参数:
className- 类名method- 方法名- 返回:
- {实例对象|方法返回值}
- 抛出:
ReflectException- ReflectException
-
executeMethodByParam
public static Object executeMethodByParam(String className, String method, Class<?>[] parameterType, Object[] paramValue) throws ReflectException 执行带参数的方法- 参数:
className- 类名method- 执行方法parameterType- 参数类型paramValue- 参数值- 返回:
- Object
- 抛出:
ReflectException- ReflectException
-
executeMethod
执行方法- 参数:
instance- 实例对象method- 执行方法- 返回:
- 方法返回值
- 抛出:
ReflectException- ReflectException
-
executeMethodByParam
public static Object executeMethodByParam(Object instance, String method, Class<?>[] parameterType, Object[] paramValue) throws ReflectException 执行带参数的方法- 参数:
instance- 实例对象method- 执行方法parameterType- 参数类型paramValue- 参数值- 返回:
- Object
- 抛出:
ReflectException- ReflectException
-
setFieldValue
public static void setFieldValue(Object instance, String fieldName, Object fieldValue) throws ReflectException 设置变量值- 参数:
instance- 实例对象fieldName- 属性值fieldValue- 属性值- 抛出:
ReflectException- ReflectException
-
isFieldExists
判断列是否存在- 参数:
instance-fieldName-- 返回:
-
getFieldValue
设置属性值- 参数:
instance- 实例对象fieldName- 属性名称- 返回:
- 属性值
-
findAllImplementsClass
查找指定接口的所有实现类(会在shforce-开头的JAR包及目录中查找)- 参数:
interfaceClass- 接口Class对象- 返回:
- 实现类的Class集
-