Class ReflectionUtils


  • public class ReflectionUtils
    extends java.lang.Object
    Adapted from this article
    Author:
    Ian Robertson, Fabrizio Giudici
    • Constructor Summary

      Constructors 
      Constructor Description
      ReflectionUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Class<?> getClass​(java.lang.reflect.Type type)  
      static <T> java.util.List<java.lang.Class<?>> getTypeArguments​(java.lang.Class<T> baseClass, java.lang.Class<? extends T> childClass)
      Get the actual type arguments a subclass has used to extend a generic base class.
      static void injectDependencies​(java.lang.Object object, java.util.Map<java.lang.Class<?>,​java.lang.Object> beans)  
      static <T> T instantiateWithDependencies​(java.lang.Class<? extends T> type, java.util.Map<java.lang.Class<?>,​java.lang.Object> beans)
      Instantiates an object of the given class performing dependency injections through the constructor.
      • Methods inherited from class java.lang.Object

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

      • ReflectionUtils

        public ReflectionUtils()
    • Method Detail

      • getTypeArguments

        @Nonnull
        public static <T> java.util.List<java.lang.Class<?>> getTypeArguments​(@Nonnull
                                                                              java.lang.Class<T> baseClass,
                                                                              @Nonnull
                                                                              java.lang.Class<? extends T> childClass)
        Get the actual type arguments a subclass has used to extend a generic base class.
        Type Parameters:
        T - the static type of the base class
        Parameters:
        baseClass - the base class
        childClass - the subclass
        Returns:
        a list of the raw classes for the actual type arguments.
      • instantiateWithDependencies

        public static <T> T instantiateWithDependencies​(@Nonnull
                                                        java.lang.Class<? extends T> type,
                                                        @Nonnull
                                                        java.util.Map<java.lang.Class<?>,​java.lang.Object> beans)
        Instantiates an object of the given class performing dependency injections through the constructor.
        Type Parameters:
        T - the generic type of the object to instantiate
        Parameters:
        type - the dynamic type of the object to instantiate; it is expected to have a single constructor
        beans - the pool of objects to instantiate
        Returns:
        the new instance
        Throws:
        java.lang.RuntimeException - if something fails
        Since:
        3.2-ALPHA-17
      • injectDependencies

        public static void injectDependencies​(@Nonnull
                                              java.lang.Object object,
                                              @Nonnull
                                              java.util.Map<java.lang.Class<?>,​java.lang.Object> beans)
        Since:
        3.2-ALPHA-17
      • getClass

        @CheckForNull
        public static java.lang.Class<?> getClass​(@Nonnull
                                                  java.lang.reflect.Type type)