public final class UtilReflection extends Object
Modifier and Type | Method and Description |
---|---|
static <T> T |
create(Class<?> type,
Class<?>[] paramTypes,
Object... params)
Create a class instance with its parameters.
|
static <T> T |
createReduce(Class<?> type,
Object... params)
Create a class instance with its parameters.
|
static Constructor<?> |
getCompatibleConstructor(Class<?> type,
Class<?>[] paramTypes)
Get a compatible constructor with the following parameters.
|
static Constructor<?> |
getCompatibleConstructorParent(Class<?> type,
Class<?>[] paramTypes)
Get a compatible constructor with the following parameters considering parent side.
|
static <T> T |
getField(Object object,
String name)
Get the field by reflection.
|
static Collection<Class<?>> |
getInterfaces(Class<?> object,
Class<?> base)
Get all declared interfaces from object.
|
static <T> T |
getMethod(Object object,
String name,
Object... params)
Get method and call its return value with parameters.
|
static Class<?>[] |
getParamTypes(Object... arguments)
Get the parameter types as array.
|
static void |
setAccessible(AccessibleObject object,
boolean accessible)
Set the object accessibility with an access controller.
|
public static <T> T create(Class<?> type, Class<?>[] paramTypes, Object... params) throws NoSuchMethodException
T
- The element type used.type
- The class type to instantiate.paramTypes
- The class base type for each parameter.params
- The constructor parameters.NoSuchMethodException
- If no constructor found.LionEngineException
- If unable to create the instance or type is null
.public static <T> T createReduce(Class<?> type, Object... params) throws NoSuchMethodException
T
- The element type used.type
- The class type.params
- The maximum parameters in sequential order.NoSuchMethodException
- If no constructor found.public static Class<?>[] getParamTypes(Object... arguments)
arguments
- The arguments list.public static Constructor<?> getCompatibleConstructor(Class<?> type, Class<?>[] paramTypes) throws NoSuchMethodException
type
- The class type.paramTypes
- The parameters types.NoSuchMethodException
- If no constructor found.public static Constructor<?> getCompatibleConstructorParent(Class<?> type, Class<?>[] paramTypes) throws NoSuchMethodException
type
- The class type.paramTypes
- The parameters types.NoSuchMethodException
- If no constructor found.public static <T> T getMethod(Object object, String name, Object... params)
T
- The object type.object
- The object caller.name
- The method name.params
- The method parameters.public static <T> T getField(Object object, String name)
T
- The field type.object
- The object to use.name
- The field name.LionEngineException
- If field not found.public static void setAccessible(AccessibleObject object, boolean accessible)
object
- The accessible object.accessible
- true
if accessible, false
else.public static Collection<Class<?>> getInterfaces(Class<?> object, Class<?> base)
object
- The object reference.base
- The minimum base interface.Copyright © 2017 Byron 3D Games Studio. All rights reserved.