Class ReflectionUtils

java.lang.Object
it.tidalwave.util.ReflectionUtils

public class ReflectionUtils extends Object
Adapted from this article
Author:
Ian Robertson, Fabrizio Giudici
  • Constructor Details

    • ReflectionUtils

      public ReflectionUtils()
  • Method Details

    • getTypeArguments

      @Nonnull public static <T> List<Class<?>> getTypeArguments(@Nonnull Class<T> baseClass, @Nonnull 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 Class<? extends T> type, @Nonnull Map<Class<?>,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:
      RuntimeException - if something fails
      Since:
      3.2-ALPHA-17
    • injectDependencies

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

      @CheckForNull public static Class<?> getClass(@Nonnull Type type)