public final class Reflects extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static Object |
fastInvoke(Object obj,
String methodName,
Class<?>[] parameterTypes,
Object[] args)
Invokes the underlying method, fast invoke using ASM.
|
static Class<?>[] |
findMatchingParameterTypes(List<Class<?>[]> parameterTypesList,
Object[] args)
Find an array of parameter
Types that matches the given compatible parameters. |
static <Ext> Pair<Class<?>[],Ext> |
findMatchingParameterTypesExt(List<Pair<Class<?>[],Ext>> pairs,
Object[] args)
Find an array of parameter
Types that matches the given compatible parameters. |
static Field |
getField(Class<?> clazz,
String name)
Returns a
Field object that reflects the specified declared field
of the Class or interface represented by this Class object. |
static Object |
getStaticValue(Class<?> clazz,
String name)
Returns the static value by name, on the specified
Class. |
static Object |
getTypeDefaultValue(Class<?> clazz)
Returns the default value for the specified class.
|
static Object |
getValue(Object o,
String name)
Returns the value by name, on the specified object.
|
static boolean |
isAssignable(Class<?>[] classArray,
Class<?>[] toClassArray,
boolean autoboxing)
|
static boolean |
isAssignable(Class<?> cls,
Class<?> toClass,
boolean autoboxing)
|
static <T> T |
newInstance(Class<T> clazz)
Creates a new object.
|
static <T> T |
newInstance(Class<T> clazz,
boolean constructorCalled)
Creates a new object.
|
static Class<?> |
primitiveToWrapper(Class<?> cls)
Converts the specified primitive
Class object to its corresponding
wrapper Class object. |
static void |
setStaticValue(Class<?> clazz,
String name,
Object value)
Sets new value by name, on the specified
Class. |
static void |
setValue(Object o,
String name,
Object value)
Sets new value by name, on the specified object.
|
static String |
simpleClassName(Class<?> clazz)
Generates a simplified name from a
Class. |
static String |
simpleClassName(Object o)
The shortcut to
simpleClassName(o.getClass()). |
static Class<?> |
wrapperToPrimitive(Class<?> cls)
Converts the specified wrapper
Class to its corresponding primitive
class. |
public static <T> T newInstance(Class<T> clazz)
clazz - the class to instantiatepublic static <T> T newInstance(Class<T> clazz, boolean constructorCalled)
clazz - the class to instantiateconstructorCalled - whether or not any constructor being calledpublic static Object fastInvoke(Object obj, String methodName, Class<?>[] parameterTypes, Object[] args)
obj - the object the underlying method is invoked frommethodName - the method name this objectparameterTypes - the parameter types for the method this objectargs - the arguments used for the method callobj with parameterspublic static Field getField(Class<?> clazz, String name) throws NoSuchFieldException
Field object that reflects the specified declared field
of the Class or interface represented by this Class object.
The name parameter is a String that specifies the
simple name of the desired field.clazz - classname - field nameField object for the specified field in this classNoSuchFieldException - if a field with the specified name is not found.public static Object getStaticValue(Class<?> clazz, String name)
Class. The value is
automatically wrapped in an object if it has a primitive type.clazz - the specified classname - the name of the represented field in classpublic static void setStaticValue(Class<?> clazz, String name, Object value)
Class. The new value is
automatically unwrapped if the underlying field has
a primitive type.clazz - the specified classname - the name of the the field in classvalue - the new value for the field in classpublic static Object getValue(Object o, String name)
o - the specified objectname - the name of the represented field in objectpublic static void setValue(Object o, String name, Object value)
o - the specified objectname - the name of the the field in objectvalue - the new value for the field in objectpublic static Object getTypeDefaultValue(Class<?> clazz)
public static String simpleClassName(Object o)
simpleClassName(o.getClass()).public static String simpleClassName(Class<?> clazz)
Class. Similar to Class.getSimpleName(),
but it works fine with anonymous classes.public static Class<?>[] findMatchingParameterTypes(List<Class<?>[]> parameterTypesList, Object[] args)
Types that matches the given compatible parameters.public static <Ext> Pair<Class<?>[],Ext> findMatchingParameterTypesExt(List<Pair<Class<?>[],Ext>> pairs, Object[] args)
Types that matches the given compatible parameters.public static boolean isAssignable(Class<?>[] classArray, Class<?>[] toClassArray, boolean autoboxing)
public static Class<?> primitiveToWrapper(Class<?> cls)
Class object to its corresponding
wrapper Class object.Copyright © 2018. All rights reserved.