com.foxinmy.weixin4j.util
Class ReflectionUtil

java.lang.Object
  extended by com.foxinmy.weixin4j.util.ReflectionUtil

public class ReflectionUtil
extends Object

Author:
jinyu(foxinmy@gmail.com) , 2012-10-26

Constructor Summary
ReflectionUtil()
           
 
Method Summary
static Field getAccessibleField(Object object, String fieldName)
           
static Set<Field> getAllField(Class<?> clazz)
           
static Class<?> getFieldGenericType(Object obj, String fieldName)
          获取字段的泛型参数类型
static String getFieldType(Object object, String fieldName)
           
static Object getFieldValue(Object object, String fieldName)
          获取对象属性值,无视private/protected/getter
static String getPackageName(Object obj)
          获取包包名
static Object invokeGetterMethod(Object object, String propertyName)
          调用Getter方法
static Object invokeMethod(Object object, String propertyName)
          调用方法
static Object invokeMethod(Object object, String propertyName, Object... args)
           
static void invokeSetterMethod(Object object, String propertyName, Object propertyValue)
          调用Setter方法
static void invokeSetterMethod(Object object, String propertyName, Object propertyValue, Class<?> setterMethodClass)
          调用Setter方法
static void setFieldValue(Object object, String fieldName, Object value)
          设置对象属性值,无视private/protected/setter
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtil

public ReflectionUtil()
Method Detail

getPackageName

public static String getPackageName(Object obj)
获取包包名

Parameters:
obj -
Returns:

getFieldGenericType

public static Class<?> getFieldGenericType(Object obj,
                                           String fieldName)
获取字段的泛型参数类型

Parameters:
obj -
fieldName -
Returns:

invokeMethod

public static Object invokeMethod(Object object,
                                  String propertyName)
调用方法

Parameters:
object - 对象
propertyName - 属性名称

invokeMethod

public static Object invokeMethod(Object object,
                                  String propertyName,
                                  Object... args)

invokeGetterMethod

public static Object invokeGetterMethod(Object object,
                                        String propertyName)
                                 throws Exception
调用Getter方法

Parameters:
object - 对象
propertyName - 属性名称
Throws:
SecurityException
NoSuchMethodException
InvocationTargetException
IllegalArgumentException
IllegalAccessException
Exception

invokeSetterMethod

public static void invokeSetterMethod(Object object,
                                      String propertyName,
                                      Object propertyValue)
调用Setter方法

Parameters:
object - 对象
propertyName - 属性名称
propertyValue - 属性值

invokeSetterMethod

public static void invokeSetterMethod(Object object,
                                      String propertyName,
                                      Object propertyValue,
                                      Class<?> setterMethodClass)
调用Setter方法

Parameters:
object - 对象
propertyName - 属性名称
propertyValue - 属性值
setterMethodClass - 参数类型

getFieldValue

public static Object getFieldValue(Object object,
                                   String fieldName)
获取对象属性值,无视private/protected/getter

Parameters:
object - 对象
fieldName - 属性名称

setFieldValue

public static void setFieldValue(Object object,
                                 String fieldName,
                                 Object value)
设置对象属性值,无视private/protected/setter

Parameters:
object - 对象
fieldName - 属性名称

getFieldType

public static String getFieldType(Object object,
                                  String fieldName)

getAccessibleField

public static Field getAccessibleField(Object object,
                                       String fieldName)

getAllField

public static Set<Field> getAllField(Class<?> clazz)


Copyright © 2014–2017. All rights reserved.