Class 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 Detail

      • ReflectionHelper

        public ReflectionHelper()
    • 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 construct
        parameterTypes - 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 type
        clzWrapper - 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 the Method that is compatible to the supplied parameter types.
        Parameters:
        clazz - the Class on which to find the Method
        methodName - the method name
        arguments - the arguments for the Method
        Returns:
        a compatible Method or null if one can't be found
      • 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 or null 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 type
        y - the second type
        Returns:
        if a value of type y is assignable to the type x
      • isCompatibleMethod

        public static boolean isCompatibleMethod​(Method method,
                                                 int modifiers,
                                                 Type returnType,
                                                 Type... parameterTypes)
        Determines if the signature of a Method is compatible with the specified parameters.
        Parameters:
        method - the Method to check against
        modifiers - the desired modifiers of the Method
        returnType - the desired return type of the Method
        parameterTypes - the parameters to the Method
        Returns:
        true if the Method signature is compatible with the specified parameters, false otherwise