com.baidu.unbiz.fluentvalidator.util
类 ReflectionUtil

java.lang.Object
  继承者 com.baidu.unbiz.fluentvalidator.util.ReflectionUtil

public class ReflectionUtil
extends Object

反射工具类

作者:
zhangxu

构造方法摘要
ReflectionUtil()
           
 
方法摘要
static
<A extends Annotation>
A
getAnnotation(Field field, Class<A> annotationType)
          获取Field上的注解
static Field[] getAnnotationFields(Class<?> clazz, Class<? extends Annotation> annotationClass)
          获取所有包含指定AnnotationField数组
static Method getGetterMethod(Class<?> clazz, Field field)
          获取getter方法
static String getGetterMethodName(Field field)
          获取getter方法名
static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
          获取方法
static boolean hasSuperClass(Class<?> clazz)
          判断是否有超类
static
<T> T
invokeMethod(Method method, Object target, Object... args)
          方法调用,如果clazznull,返回null

如果methodnull,返回null

如果targetnull,则为静态方法

 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

ReflectionUtil

public ReflectionUtil()
方法详细信息

getAnnotationFields

public static Field[] getAnnotationFields(Class<?> clazz,
                                          Class<? extends Annotation> annotationClass)
获取所有包含指定AnnotationField数组

参数:
clazz - 查找类
annotationClass - 注解类名
返回:
Field数组

getAnnotation

public static <A extends Annotation> A getAnnotation(Field field,
                                                     Class<A> annotationType)
获取Field上的注解

参数:
field - 属性
annotationType - 注解类型
返回:
注解对象

hasSuperClass

public static boolean hasSuperClass(Class<?> clazz)
判断是否有超类

参数:
clazz - 目标类
返回:
如果有返回true,否则返回false

getGetterMethod

public static Method getGetterMethod(Class<?> clazz,
                                     Field field)
获取getter方法

参数:
clazz - 类
field - 属性
返回:
getter方法

getGetterMethodName

public static String getGetterMethodName(Field field)
获取getter方法名

参数:
field - 属性
返回:
getter方法名

getMethod

public static Method getMethod(Class<?> clazz,
                               String methodName,
                               Class<?>... parameterTypes)
获取方法

参数:
clazz - 类
methodName - 方法名
parameterTypes - 方法参数
返回:
方法

invokeMethod

public static <T> T invokeMethod(Method method,
                                 Object target,
                                 Object... args)
方法调用,如果clazznull,返回null

如果methodnull,返回null

如果targetnull,则为静态方法

参数:
method - 调用的方法
target - 目标对象
args - 方法的参数值
返回:
调用结果


Copyright © 2015–2016 neoremind. All rights reserved.