Package com.tangosol.util.fsm
Class ReflectionHelper
- java.lang.Object
-
- com.tangosol.util.fsm.ReflectionHelper
-
public class ReflectionHelper extends Object
A collection of utilities to assist in using Reflection to create objects.- Since:
- Coherence 12.2.1
- Author:
- Christer Fahlgren, Brian Oliver
-
-
Constructor Summary
Constructors Constructor Description ReflectionHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
createObject(String sClassName, ClassLoader classLoader)
Create an Object via reflection (using the specifiedClassLoader
).static Object
createObject(String sClassName, Object[] constructorParameterList, ClassLoader classLoader)
Create an Object via reflection (using the specifiedClassLoader
).protected static Class<?>[]
getClassArrayFromObjectArray(Object[] objectArray)
Returns an array of Class objects representing the class of the objects in the parameter.static Constructor<?>
getCompatibleConstructor(Class<?> clazz, Class<?>[] parameterTypes)
Get a compatible constructor to the supplied parameter types.static Method
getCompatibleMethod(Class<?> clazz, String methodName, Object... arguments)
Obtains theMethod
that is compatible to the supplied parameter types.static Class<?>
getConcreteType(Type type)
Obtains the concrete (non-parameterized)Class
given a specified (possibly parameterized) type.static boolean
isAssignableFrom(Type x, Type y)
Determines if two types are assignment compatible, that is, the type of y can be assigned to type x.static boolean
isAssignablePrimitive(Class<?> clzPrimitive, Class<?> clzWrapper)
Determines if a primitive type is assignable to a wrapper type.static boolean
isCompatibleMethod(Method method, int modifiers, Type returnType, Type... parameterTypes)
Determines if the signature of aMethod
is compatible with the specified parameters.
-
-
-
Method Detail
-
getCompatibleConstructor
public static Constructor<?> getCompatibleConstructor(Class<?> clazz, Class<?>[] parameterTypes)
Get a compatible constructor to the supplied parameter types.- Parameters:
clazz
- the class which we want to constructparameterTypes
- the types required of the constructor- Returns:
- a compatible constructor or null if none exists
-
isAssignablePrimitive
public static boolean isAssignablePrimitive(Class<?> clzPrimitive, Class<?> clzWrapper)
Determines if a primitive type is assignable to a wrapper type.- Parameters:
clzPrimitive
- a primitive class typeclzWrapper
- a wrapper class type- Returns:
- true if primitive and wrapper are assignment compatible
-
getCompatibleMethod
public static Method getCompatibleMethod(Class<?> clazz, String methodName, Object... arguments)
Obtains theMethod
that is compatible to the supplied parameter types.
-
createObject
public static Object createObject(String sClassName, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
Create an Object via reflection (using the specified
ClassLoader
).- Parameters:
sClassName
- the name of the class to instantiate.classLoader
- theClassLoader
to use to load the class.- Returns:
- A new instance of the class specified by the className
- Throws:
ClassNotFoundException
- if the class is not foundNoSuchMethodException
- if there is no such constructorInstantiationException
- if it failed to instantiateIllegalAccessException
- if security doesn't allow the callInvocationTargetException
- if the constructor failed
-
createObject
public static Object createObject(String sClassName, Object[] constructorParameterList, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
Create an Object via reflection (using the specified
ClassLoader
).- Parameters:
sClassName
- the name of the class to instantiate.constructorParameterList
- the set of parameters to pass to the constructorclassLoader
- theClassLoader
to use to load the class.- Returns:
- A new instance of the class specified by the className
- Throws:
ClassNotFoundException
- if the class is not foundNoSuchMethodException
- if there is no such constructorInstantiationException
- if it failed to instantiateIllegalAccessException
- if security doesn't allow the callInvocationTargetException
- if the constructor failed
-
getClassArrayFromObjectArray
protected static Class<?>[] getClassArrayFromObjectArray(Object[] objectArray)
Returns an array of Class objects representing the class of the objects in the parameter.- Parameters:
objectArray
- the array of Objects- Returns:
- an array of Classes representing the class of the Objects
-
getConcreteType
public static Class<?> getConcreteType(Type type)
Obtains the concrete (non-parameterized)Class
given a specified (possibly parameterized) type.- Parameters:
type
- the type- Returns:
- the concrete
Class
ornull
if there is no concrete class.
-
isAssignableFrom
public static boolean isAssignableFrom(Type x, Type y)
Determines if two types are assignment compatible, that is, the type of y can be assigned to type x.- Parameters:
x
- the first typey
- the second type- Returns:
- if a value of type y is assignable to the type x
-
-