Example #1
0
 /** 设置成员变量 */
 public static void setField(Object obj, Field field, Object value) {
   try {
     field.setAccessible(true);
     field.set(obj, value);
   } catch (Exception e) {
     LoggerUtil.logger().error("set field failure", e);
     throw new RuntimeException(e);
   }
 }
Example #2
0
 /** 创建实例 */
 public static Object newInstance(String className) {
   try {
     Class clazz = Class.forName(className);
     return newInstance(clazz);
   } catch (ClassNotFoundException e) {
     LoggerUtil.logger().error(" new Instance by class name failure", e);
     throw new RuntimeException(e);
   }
 }
Example #3
0
 /** 创建实例 */
 public static Object newInstance(Class<?> clazz) {
   Object instance;
   try {
     instance = clazz.newInstance();
   } catch (Exception e) {
     LoggerUtil.logger().error("new instance failure", e);
     throw new RuntimeException(e);
   }
   return instance;
 }
Example #4
0
 /** 调用方法 */
 public static Object invokeMethod(Object obj, Method method, Object... args) {
   Object result;
   try {
     method.setAccessible(true);
     result = method.invoke(obj, args);
   } catch (Exception e) {
     LoggerUtil.logger().error("invoke method failure", e);
     throw new RuntimeException(e);
   }
   return result;
 }