@Immutable public final class GenericReflection extends Object
SuppressWarnings("unchecked") annotation.| Modifier and Type | Method and Description |
|---|---|
static <DATATYPE> Constructor<DATATYPE> |
findConstructor(DATATYPE aObj,
Class<?>... aCtorArgs) |
static Class<?>[] |
getClassArray(Object... aObjs)
Get an array with all the classes of the passed object array.
|
static <DATATYPE> Class<DATATYPE> |
getClassFromName(String sName) |
static <DATATYPE> Class<DATATYPE> |
getClassFromNameSafe(String sName)
Get the class of the given name
|
static <RETURNTYPE> |
invokeMethod(Object aSrcObj,
String sMethodName,
Class<?>[] aArgClasses,
Object[] aArgs) |
static <RETURNTYPE> |
invokeMethod(Object aSrcObj,
String sMethodName,
Object... aArgs)
This method dynamically invokes the method with the given name on the given
object.
|
static <RETURNTYPE> |
invokeStaticMethod(Class<?> aClass,
String sMethodName,
Class<?>[] aArgClasses,
Object[] aArgs) |
static <RETURNTYPE> |
invokeStaticMethod(Class<?> aClass,
String sMethodName,
Object... aArgs) |
static <RETURNTYPE> |
invokeStaticMethod(String sClassName,
String sMethodName,
Class<?>[] aArgClasses,
Object[] aArgs) |
static <RETURNTYPE> |
invokeStaticMethod(String sClassName,
String sMethodName,
Object... aArgs) |
static <DATATYPE> DATATYPE |
newInstance(Class<? extends DATATYPE> aClass) |
static <DATATYPE> DATATYPE |
newInstance(DATATYPE aObj)
Create a new instance of the class identified by the passed object.
|
static <DATATYPE> DATATYPE |
newInstance(String sClassName,
Class<DATATYPE> aDesiredType) |
static <DATATYPE> DATATYPE |
newInstance(String sClassName,
Class<DATATYPE> aDesiredType,
ClassLoader aClassLoaderToUse) |
static <SRCTYPE,DSTTYPE> |
uncheckedCast(SRCTYPE aObject) |
public static <SRCTYPE,DSTTYPE> DSTTYPE uncheckedCast(@Nullable SRCTYPE aObject)
@Nonnull public static <DATATYPE> Class<DATATYPE> getClassFromName(@Nonnull String sName) throws ClassNotFoundException
ClassNotFoundException@Nullable public static <DATATYPE> Class<DATATYPE> getClassFromNameSafe(@Nonnull String sName)
DATATYPE - The return typesName - The name to be resolved.null if the class could not be resolved@Nonnull public static Class<?>[] getClassArray(@Nullable Object... aObjs)
aObjs - The object array. May be null. No contained element may
be null.null array of classes.@Nullable public static <RETURNTYPE> RETURNTYPE invokeMethod(@Nonnull Object aSrcObj, @Nonnull String sMethodName, @Nullable Object... aArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
aSrcObj - The source object on which the method is to be invoked. May not be
null.sMethodName - The method to be invoked.aArgs - The arguments to be passed into the method. May be null
. If not null, the members of the array may not be
null because otherwise the classes of the arguments
cannot be determined and will throw an Exception!null for
void methods.NoSuchMethodException - Thrown by reflectionIllegalAccessException - Thrown by reflectionInvocationTargetException - Thrown by reflection@Nullable public static <RETURNTYPE> RETURNTYPE invokeMethod(@Nonnull Object aSrcObj, @Nonnull String sMethodName, @Nullable Class<?>[] aArgClasses, @Nullable Object[] aArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
@Nullable public static <RETURNTYPE> RETURNTYPE invokeStaticMethod(@Nonnull String sClassName, @Nonnull String sMethodName, @Nullable Object... aArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
@Nullable public static <RETURNTYPE> RETURNTYPE invokeStaticMethod(@Nonnull Class<?> aClass, @Nonnull String sMethodName, @Nullable Object... aArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
@Nullable public static <RETURNTYPE> RETURNTYPE invokeStaticMethod(@Nonnull String sClassName, @Nonnull String sMethodName, @Nullable Class<?>[] aArgClasses, @Nullable Object[] aArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
@Nullable public static <RETURNTYPE> RETURNTYPE invokeStaticMethod(@Nonnull Class<?> aClass, @Nonnull String sMethodName, @Nullable Class<?>[] aArgClasses, @Nullable Object[] aArgs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
@Nonnull public static <DATATYPE> Constructor<DATATYPE> findConstructor(@Nonnull DATATYPE aObj, Class<?>... aCtorArgs) throws NoSuchMethodException
NoSuchMethodException@Nonnull public static <DATATYPE> DATATYPE newInstance(@Nonnull DATATYPE aObj) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException
DATATYPE - The type of object to be created.aObj - The object from which the class should be used.IllegalAccessException - Reflection exceptionNoSuchMethodException - Reflection exceptionInvocationTargetException - Reflection exceptionInstantiationException - Reflection exception@Nullable public static <DATATYPE> DATATYPE newInstance(@Nullable Class<? extends DATATYPE> aClass)
@Nullable public static <DATATYPE> DATATYPE newInstance(@Nullable String sClassName, @Nullable Class<DATATYPE> aDesiredType)
Copyright © 2006–2015 phloc systems. All rights reserved.