public class Reflects extends Object
| 构造器和说明 |
|---|
Reflects() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
extractFieldName(Member member) |
static String |
extractFieldName(Method method) |
static Collection<Field> |
filterFields(Field[] fields,
int... excludedModifiers) |
static Collection<Field> |
getAllDeclaredFields(Class clazz) |
static Collection<Field> |
getAllDeclaredFields(Class clazz,
boolean containsStatic) |
static Set<Class> |
getAllInterfaces(Class clazz) |
static Collection<Field> |
getAllPublicFields(Class clazz,
boolean containsStatic) |
static Collection<Field> |
getAllPublicInstanceFields(Class clazz) |
static Set<Class> |
getAllSuperClass(Class clazz) |
static List<Method> |
getAnnotatedMethods(Class<?> type,
Class<? extends Annotation> annotation) |
static <E extends Annotation> |
getAnnotation(AnnotatedElement annotatedElement,
Class<E> annotationClass)
Returns this element's annotation for the specified type if
such an annotation is present, else null.
|
static Annotation[] |
getAnnotations(AnnotatedElement annotatedElement)
Returns all annotations present on this element.
|
static Field |
getAnyField(Class clazz,
String fieldName) |
static <V> V |
getAnyFieldValue(Object object,
String fieldName,
boolean force,
boolean throwException) |
static <V> V |
getAnyFieldValueForcedIfPresent(Object object,
String fieldName) |
static Method |
getAnyMethod(Class clazz,
String methodName,
Class... parameterTypes) |
static URL |
getCodeLocation(Class clazz) |
static String |
getCodeLocationString(Class clazz) |
static <E> Class<E> |
getComponentType(E[] array) |
static <E> Constructor<E> |
getConstructor(Class<E> clazz,
Class... parameterTypes) |
static ConstructorParameter |
getConstructorParameter(Constructor constructor,
int index) |
static ConstructorParameter |
getConstructorParameter(String supplierName,
Constructor constructor,
int index) |
static List<ConstructorParameter> |
getConstructorParameters(Constructor constructor) |
static List<ConstructorParameter> |
getConstructorParameters(String supplierName,
Constructor constructor) |
static <E extends Annotation> |
getDeclaredAnnotation(AnnotatedElement annotatedElement,
Class<E> annotationClass) |
static List<Annotation> |
getDeclaredAnnotations(AnnotatedElement annotatedElement)
Returns all annotations that are directly present on this
element.
|
static Field |
getDeclaredField(Class clazz,
String fieldName) |
static <V> V |
getDeclaredFieldValue(Object object,
String fieldName,
boolean force,
boolean throwException) |
static <V> V |
getDeclaredFieldValueForcedIfPresent(Object object,
String fieldName) |
static Method |
getDeclaredMethod(Class clazz,
String methodName,
Class... parameterTypes) |
static <V> V |
getFieldValue(Field field,
Object object,
boolean force,
boolean throwException) |
static String |
getFQNClassName(Class clazz) |
static Method |
getGetter(Class clazz,
String field)
找到 public 的, 非 static 的 Getter
|
static String |
getGetter(String s) |
static String |
getIsGetter(String s) |
static String |
getJvmSignature(Class clazz) |
static MethodParameter |
getMethodParameter(Method method,
int index) |
static MethodParameter |
getMethodParameter(String supplierName,
Method method,
int index) |
static List<MethodParameter> |
getMethodParameters(Method method) |
static List<MethodParameter> |
getMethodParameters(String supplierName,
Method method) |
static String |
getMethodString(Class clazz,
String methodName,
Class[] parameterTypes) |
static String |
getMethodString(Method method) |
static String |
getMethodString(String clazzFQN,
String methodName,
Class returnType,
Class[] parameterTypes) |
static String |
getPackageName(Class clazz) |
static String |
getPackageName(String classFullName) |
static Field |
getPublicField(Class clazz,
String fieldName) |
static <V> V |
getPublicFieldValue(Object object,
String fieldName,
boolean throwException) |
static <V> V |
getPublicFieldValueForcedIfPresent(Object object,
String fieldName) |
static Method |
getPublicMethod(Class clazz,
String methodName,
Class... parameterTypes) |
static Method |
getSetter(Class clazz,
String field) |
static Method |
getSetter(Class clazz,
String field,
Class parameterType) |
static String |
getSetter(String s)
This new method 'slightly' outperforms the old method, it was
essentially a perfect example of me wasting my time and a
premature optimization.
|
static String |
getSimpleClassName(Class clazz) |
static String |
getSimpleClassName(Object obj) |
static Field |
getStaticField(Class clazz,
String fieldName) |
static String |
getTypeName(Class type) |
static <E extends Annotation> |
hasAnnotation(AnnotatedElement annotatedElement,
Class<E> annotationClass) |
static <E> boolean |
hasConstructor(Class<E> clazz,
Class... parameterTypes) |
static boolean |
hasGetter(Field field) |
static boolean |
hasSetter(Field field) |
static Iterable<Class<?>> |
hierarchy(Class<?> type)
Get an
Iterable that can iterate over a class hierarchy in ascending (subclass to superclass) order,
excluding interfaces. |
static Iterable<Class<?>> |
hierarchy(Class<?> type,
boolean excludeInterfaces)
Get an
Iterable that can iterate over a class hierarchy in ascending (subclass to superclass) order. |
static <V> V |
invoke(Method method,
Object object,
Object[] parameters,
boolean force,
boolean throwException) |
static <V> V |
invokeAnyMethod(Object object,
String methodName,
Class[] parameterTypes,
Object[] parameters,
boolean force,
boolean throwException) |
static <V> V |
invokeAnyMethodForcedIfPresent(Object object,
String methodName,
Class[] parameterTypes,
Object[] parameters) |
static <V> V |
invokeAnyStaticMethod(Class clazz,
String methodName,
Class[] parameterTypes,
Object[] parameters,
boolean force,
boolean throwException) |
static <V> V |
invokeAnyStaticMethod(String clazz,
String methodName,
Class[] parameterTypes,
Object[] parameters,
boolean force,
boolean throwException) |
static <V> V |
invokeDeclaredMethod(Object object,
String methodName,
Class[] parameterTypes,
Object[] parameters,
boolean force,
boolean throwException) |
static <V> V |
invokeDeclaredMethodForcedIfPresent(Object object,
String methodName,
Class[] parameterTypes,
Object[] parameters) |
static <V> V |
invokeGetterOrFiled(Object object,
String field,
boolean force,
boolean throwException) |
static <V> V |
invokePublicMethod(Object object,
String methodName,
Class[] parameterTypes,
Object[] parameters,
boolean force,
boolean throwException) |
static <V> V |
invokePublicMethodForcedIfPresent(Object object,
String methodName,
Class[] parameterTypes,
Object[] parameters) |
static boolean |
isAnnotationPresent(AnnotatedElement annotatedElement,
Class<? extends Annotation> annotationClass)
Returns true if an annotation for the specified type
is present on this element, else false.
|
static boolean |
isAnonymous(Class clazz) |
static boolean |
isAnonymousOrLocal(Class<?> clazz) |
static boolean |
isConcrete(Class clazz) |
static boolean |
isEqualsMethod(Method method)
Determine whether the given method is an "equals" method.
|
static boolean |
isGetter(Method method) |
static boolean |
isGetterOrSetter(Method method) |
static boolean |
isHashCodeMethod(Method method)
Determine whether the given method is a "hashCode" method.
|
static boolean |
isImplementsInterface(Class clazz,
Class intf)
Determine if the given class implements the given interface.
|
static boolean |
isInnerClass(Class<?> clazz) |
static <T> boolean |
isInstance(T object,
Class targetType)
判断 obj 是否是 targetType 的实例
|
static <T> boolean |
isInstance(T object,
String classFQN) |
static boolean |
isLambda(Class<?> clazz) |
static boolean |
isLocal(Class clazz) |
static boolean |
isObjectMethod(Method method)
Determine whether the given method is originally declared by
Object. |
static boolean |
isOverrideEquals(Class clazz)
Determine if the given class defines an
Object.equals(java.lang.Object) override. |
static boolean |
isOverrideHashCode(Class clazz)
Determine if the given class defines a
Object.hashCode() override. |
static boolean |
isSetter(Method method) |
static boolean |
isStatic(Class<?> clazz) |
static boolean |
isSubClass(Class parent,
Class child) |
static boolean |
isSubClassOrEquals(Class parent,
Class child) |
static boolean |
isSubClassOrEquals(String parent,
Class child) |
static boolean |
isSubClassOrEquals(String parent,
Class child,
boolean checkSuperClass,
boolean checkInterfaces) |
static boolean |
isToStringMethod(Method method)
Determine whether the given method is a "toString" method.
|
static boolean |
makeAccessible(Field field) |
static Class<? extends Member> |
memberType(Member member) |
static <E> E |
newInstance(Class<E> clazz) |
static <E> E |
newInstance(Class<E> clazz,
Class[] parameterTypes,
Object... parameters) |
static <E> E |
newInstance(Constructor<E> constructor,
Object... parameters) |
static void |
setAnyFieldValue(Object object,
String fieldName,
Object value,
boolean force,
boolean throwException) |
static void |
setDeclaredFieldValue(Object object,
String fieldName,
Object value,
boolean force,
boolean throwException) |
static void |
setFieldValue(Field field,
Object target,
Object value,
boolean force,
boolean throwException) |
static void |
setPublicFieldValue(Object object,
String fieldName,
Object value,
boolean force,
boolean throwException) |
public static Iterable<Class<?>> hierarchy(@NonNull Class<?> type)
Iterable that can iterate over a class hierarchy in ascending (subclass to superclass) order,
excluding interfaces.type - the type to get the class hierarchy frompublic static Iterable<Class<?>> hierarchy(@NonNull Class<?> type, boolean excludeInterfaces)
Iterable that can iterate over a class hierarchy in ascending (subclass to superclass) order.type - the type to get the class hierarchy fromexcludeInterfaces - switch indicating whether to include or exclude interfacespublic static boolean isAnnotationPresent(@NonNull AnnotatedElement annotatedElement, @NonNull Class<? extends Annotation> annotationClass)
public static <E extends Annotation> boolean hasAnnotation(@NonNull AnnotatedElement annotatedElement, @NonNull Class<E> annotationClass)
public static <E extends Annotation> E getAnnotation(@NonNull AnnotatedElement annotatedElement, @NonNull Class<E> annotationClass)
public static <E extends Annotation> E getDeclaredAnnotation(@NonNull AnnotatedElement annotatedElement, @NonNull Class<E> annotationClass)
public static Annotation[] getAnnotations(@NonNull AnnotatedElement annotatedElement)
public static List<Annotation> getDeclaredAnnotations(@NonNull AnnotatedElement annotatedElement)
public static Field getDeclaredField(@NonNull Class clazz, @NonNull String fieldName)
public static Collection<Field> getAllDeclaredFields(@NonNull Class clazz)
public static Collection<Field> getAllDeclaredFields(@NonNull Class clazz, boolean containsStatic)
public static Collection<Field> getAllPublicInstanceFields(@NonNull Class clazz)
public static Collection<Field> getAllPublicFields(@NonNull Class clazz, boolean containsStatic)
public static Collection<Field> filterFields(@NonNull Field[] fields, int... excludedModifiers)
public static <V> V getPublicFieldValueForcedIfPresent(@NonNull Object object, @NonNull String fieldName)
public static <V> V getPublicFieldValue(@NonNull Object object, @NonNull String fieldName, boolean throwException)
public static <V> V getDeclaredFieldValueForcedIfPresent(@NonNull Object object, @NonNull String fieldName)
public static <V> V getDeclaredFieldValue(@NonNull Object object, String fieldName, boolean force, boolean throwException)
public static <V> V getAnyFieldValueForcedIfPresent(@NonNull Object object, @NonNull String fieldName)
public static <V> V getAnyFieldValue(@NonNull Object object, @NonNull String fieldName, boolean force, boolean throwException)
public static <V> V getFieldValue(@NonNull Field field, @NonNull Object object, boolean force, boolean throwException)
public static void setFieldValue(@NonNull Field field, @NonNull Object target, Object value, boolean force, boolean throwException)
public static void setPublicFieldValue(@NonNull Object object, @NonNull String fieldName, Object value, boolean force, boolean throwException)
public static void setDeclaredFieldValue(@NonNull Object object, @NonNull String fieldName, Object value, boolean force, boolean throwException)
public static void setAnyFieldValue(@NonNull Object object, @NonNull String fieldName, Object value, boolean force, boolean throwException)
public static <E> boolean hasConstructor(@NonNull Class<E> clazz, Class... parameterTypes)
public static <E> Constructor<E> getConstructor(@NonNull Class<E> clazz, Class... parameterTypes)
public static <E> E newInstance(@NonNull Class<E> clazz, @Nullable Class[] parameterTypes, @NonNull Object... parameters)
public static <E> E newInstance(@NonNull Constructor<E> constructor, @Nullable Object... parameters)
public static List<Method> getAnnotatedMethods(Class<?> type, Class<? extends Annotation> annotation)
public static Method getPublicMethod(@NonNull Class clazz, @NonNull String methodName, Class... parameterTypes)
public static Method getDeclaredMethod(@NonNull Class clazz, @NonNull String methodName, Class... parameterTypes)
public static Method getAnyMethod(@NonNull Class clazz, @NonNull String methodName, Class... parameterTypes)
public static <V> V invokePublicMethodForcedIfPresent(@NonNull Object object, @NonNull String methodName, @Nullable Class[] parameterTypes, @Nullable Object[] parameters)
public static <V> V invokePublicMethod(@NonNull Object object, @NonNull String methodName, @Nullable Class[] parameterTypes, @Nullable Object[] parameters, boolean force, boolean throwException)
public static <V> V invokeDeclaredMethodForcedIfPresent(@NonNull Object object, @NonNull String methodName, @Nullable Class[] parameterTypes, @Nullable Object[] parameters)
public static <V> V invokeDeclaredMethod(@NonNull Object object, @NonNull String methodName, @Nullable Class[] parameterTypes, @Nullable Object[] parameters, boolean force, boolean throwException)
public static <V> V invokeAnyMethodForcedIfPresent(@NonNull Object object, @NonNull String methodName, @Nullable Class[] parameterTypes, @Nullable Object[] parameters)
public static <V> V invokeAnyMethod(@NonNull Object object, @NonNull String methodName, @Nullable Class[] parameterTypes, @Nullable Object[] parameters, boolean force, boolean throwException)
public static <V> V invoke(@NonNull Method method, @Nullable Object object, @Nullable Object[] parameters, boolean force, boolean throwException)
public static <V> V invokeGetterOrFiled(Object object, String field, boolean force, boolean throwException)
public static <V> V invokeAnyStaticMethod(String clazz, String methodName, Class[] parameterTypes, Object[] parameters, boolean force, boolean throwException) throws ClassNotFoundException
public static <V> V invokeAnyStaticMethod(Class clazz, String methodName, Class[] parameterTypes, Object[] parameters, boolean force, boolean throwException)
public static String getMethodString(@Nullable String clazzFQN, @NonNull String methodName, @Nullable Class returnType, @Nullable Class[] parameterTypes)
public static String getMethodString(@NonNull Class clazz, @NonNull String methodName, @Nullable Class[] parameterTypes)
public static MethodParameter getMethodParameter(String supplierName, Method method, int index)
public static MethodParameter getMethodParameter(Method method, int index)
public static List<MethodParameter> getMethodParameters(String supplierName, Method method)
public static List<MethodParameter> getMethodParameters(Method method)
public static ConstructorParameter getConstructorParameter(String supplierName, Constructor constructor, int index)
public static ConstructorParameter getConstructorParameter(Constructor constructor, int index)
public static List<ConstructorParameter> getConstructorParameters(Constructor constructor)
public static List<ConstructorParameter> getConstructorParameters(String supplierName, Constructor constructor)
public static String getSetter(String s)
s - -public static boolean hasGetter(Field field)
public static boolean hasSetter(Field field)
public static Method getGetter(Class clazz, String field)
clazz - field - public static boolean isEqualsMethod(@Nullable Method method)
Object.equals(Object)public static boolean isHashCodeMethod(@Nullable Method method)
Object.hashCode()public static boolean isToStringMethod(@Nullable Method method)
Object.toString()public static boolean isObjectMethod(@Nullable Method method)
Object.public static boolean isOverrideEquals(Class clazz)
Object.equals(java.lang.Object) override.clazz - The class to checkpublic static boolean isOverrideHashCode(Class clazz)
Object.hashCode() override.clazz - The class to checkpublic static boolean isImplementsInterface(@NonNull Class clazz, @NonNull Class intf)
clazz - The class to checkintf - The interface to check it against.public static boolean isSubClassOrEquals(@NonNull Class parent, @NonNull Class child)
public static boolean isSubClassOrEquals(@NonNull String parent, @NonNull Class child)
parent - child - public static boolean isSubClassOrEquals(@NonNull String parent, @NonNull Class child, boolean checkSuperClass, boolean checkInterfaces)
parent - child - public static <T> boolean isInstance(T object,
String classFQN)
public static <T> boolean isInstance(T object,
@NonNull
Class targetType)
T - object - targetType - public static <E> Class<E> getComponentType(E[] array)
Copyright © 2022. All rights reserved.