-
public class EasyReflect
-
-
Field Summary
Fields Modifier and Type Field Description public final static EasyReflectINSTANCE
-
Method Summary
Modifier and Type Method Description final MethodfindMethod(Class<?> target, String name, Class<?> parameters)Get the specified method from this class. final Constructor<?>findConstructor(Class<?> target, Class<?> parameters)Get the specified constructor from this class. final Class<?>getClass(Class<?> target, String name)Get the specified inner class from this class. final <T extends Any> TnewInstance(Class<?> target, Object arguments)Creates a new instance using the passed arguments. final <T extends Any> TnewInstance(Constructor<?> constructor, Object arguments)Invokes this constructor, ensuring it's accessible before doing so. final <T extends Any> Tcall(Method method, Object instance, Object arguments)Invokes this method, ensuring it's accessible before doing so. final <T extends Any> TfindAndCall(Object instance, String name, Object arguments)Call the specified method from this object by searching for methods with parameters that are compatible with the passed arguments. final <T extends Any> TfindAndCallStatic(Class<?> target, String name, Object arguments)Call the specified static method from this class by searching for methods with parameters that are compatible with the passed arguments. final <T extends Any> Tget(Field field, Object instance)Get the value of this field, ensuring it's accessible before doing so. final Unitset(Field field, Object instance, Object value)Get the value of this field, ensuring it's accessible before doing so. final <T extends Any> TfindAndGet(Object instance, String name)Get the value of the specified field from this object. final UnitfindAndSet(Object instance, String name, Object value)Get the value of the specified field from this object. final <T extends Any> TfindAndGetStatic(Class<?> target, String name)Get the value of the specified static field from this object. final UnitfindAndSetStatic(Class<?> target, String name, Object value)Get the value of the specified static field from this object. -
-
Method Detail
-
findMethod
final Method findMethod(Class<?> target, String name, Class<?> parameters)
Get the specified method from this class. If no parameters are specified (and that didn't match a zero-parameter method), the only one with the passed name is returned. Throws if no matching methods exist or multiple matching methods exist.
-
findConstructor
final Constructor<?> findConstructor(Class<?> target, Class<?> parameters)
Get the specified constructor from this class. If no parameters are specified (and that didn't match a zero-parameter constructor), the only constructor is returned. Throws if no matching constructors exist or if no parameters were passed and there are multiple constructors.
-
getClass
final Class<?> getClass(Class<?> target, String name)
Get the specified inner class from this class.
-
newInstance
final <T extends Any> T newInstance(Class<?> target, Object arguments)
Creates a new instance using the passed arguments. Throws an exception if multiple constructors could be called with the specified argument types.
-
newInstance
final <T extends Any> T newInstance(Constructor<?> constructor, Object arguments)
Invokes this constructor, ensuring it's accessible before doing so.
-
call
final <T extends Any> T call(Method method, Object instance, Object arguments)
Invokes this method, ensuring it's accessible before doing so.
-
findAndCall
final <T extends Any> T findAndCall(Object instance, String name, Object arguments)
Call the specified method from this object by searching for methods with parameters that are compatible with the passed arguments. Throws if no matching methods exist or multiple matching methods exist.
-
findAndCallStatic
final <T extends Any> T findAndCallStatic(Class<?> target, String name, Object arguments)
Call the specified static method from this class by searching for methods with parameters that are compatible with the passed arguments. Throws if no matching methods exist or multiple matching methods exist.
-
get
final <T extends Any> T get(Field field, Object instance)
Get the value of this field, ensuring it's accessible before doing so.
-
set
final Unit set(Field field, Object instance, Object value)
Get the value of this field, ensuring it's accessible before doing so.
-
findAndGet
final <T extends Any> T findAndGet(Object instance, String name)
Get the value of the specified field from this object.
-
findAndSet
final Unit findAndSet(Object instance, String name, Object value)
Get the value of the specified field from this object.
-
findAndGetStatic
final <T extends Any> T findAndGetStatic(Class<?> target, String name)
Get the value of the specified static field from this object.
-
findAndSetStatic
final Unit findAndSetStatic(Class<?> target, String name, Object value)
Get the value of the specified static field from this object.
-
-
-
-