Package it.tidalwave.util
Class ReflectionUtils
java.lang.Object
it.tidalwave.util.ReflectionUtils
Adapted from this article
- Author:
- Ian Robertson, Fabrizio Giudici
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class
<?> getTypeArguments
(Class<T> baseClass, Class<? extends T> childClass) Get the actual type arguments a subclass has used to extend a generic base class.static void
injectDependencies
(Object object, Map<Class<?>, Object> beans) static <T> T
instantiateWithDependencies
(Class<? extends T> type, Map<Class<?>, Object> beans) Instantiates an object of the given class performing dependency injections through the constructor.
-
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 classchildClass
- 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 constructorbeans
- the pool of objects to instantiate- Returns:
- the new instance
- Throws:
RuntimeException
- if something fails- Since:
- 3.2-ALPHA-17
-
injectDependencies
- Since:
- 3.2-ALPHA-17
-
getClass
-