Class ReflectionUtils


  • public final class ReflectionUtils
    extends java.lang.Object
    Provides utility methods for common reflection operations.
    Author:
    Middleware Services
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Class<?> classFromType​(java.lang.reflect.Type t)
      Casts the supplied type to a class.
      static java.lang.Object getField​(java.lang.reflect.Field field, java.lang.Object object)
      Returns the value of the supplied field on the supplied object.
      static java.lang.Object invokeGetterMethod​(java.lang.reflect.Method method, java.lang.Object object)
      Invokes the supplied method on the supplied object.
      static void invokeSetterMethod​(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object value)
      Invokes the supplied method on the supplied object with the supplied value as a parameter.
      static void setField​(java.lang.reflect.Field field, java.lang.Object object, java.lang.Object value)
      Sets the supplied value of the supplied field on the supplied object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • classFromType

        public static java.lang.Class<?> classFromType​(java.lang.reflect.Type t)
        Casts the supplied type to a class.
        Parameters:
        t - to cast
        Returns:
        class cast from t
        Throws:
        java.lang.IllegalArgumentException - if t is not an instance of Class
      • getField

        public static java.lang.Object getField​(java.lang.reflect.Field field,
                                                java.lang.Object object)
        Returns the value of the supplied field on the supplied object.
        Parameters:
        field - containing the value to return
        object - that has the field
        Returns:
        value of the field on the object
        Throws:
        java.lang.IllegalArgumentException - if the field cannot be retrieved
      • setField

        public static void setField​(java.lang.reflect.Field field,
                                    java.lang.Object object,
                                    java.lang.Object value)
        Sets the supplied value of the supplied field on the supplied object.
        Parameters:
        field - of the object to set
        object - that has the field
        value - to set
        Throws:
        java.lang.IllegalArgumentException - if the field cannot be set
      • invokeGetterMethod

        public static java.lang.Object invokeGetterMethod​(java.lang.reflect.Method method,
                                                          java.lang.Object object)
        Invokes the supplied method on the supplied object.
        Parameters:
        method - to invoke
        object - that has the method
        Returns:
        value of the invoked method
        Throws:
        java.lang.IllegalArgumentException - if the method cannot be invoked
      • invokeSetterMethod

        public static void invokeSetterMethod​(java.lang.reflect.Method method,
                                              java.lang.Object object,
                                              java.lang.Object value)
        Invokes the supplied method on the supplied object with the supplied value as a parameter.
        Parameters:
        method - to invoke
        object - that has the method
        value - to set
        Throws:
        java.lang.IllegalArgumentException - if the method cannot be invoked