Package it.tidalwave.util
Class ReflectionUtils
java.lang.Object
it.tidalwave.util.ReflectionUtils
Adapted from this article
- Author:
- Ian Robertson, Fabrizio Giudici
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> Returns the class literal associated to the given type.getTypeArguments(Class<T> baseClass, Class<? extends T> childClass) Get the actual type arguments a subclass has used to extend a generic base class.static voidinjectDependencies(Object object, Map<Class<?>, Object> beans) Performs dependency injection to an object by means of field introspection.static <T> TinstantiateWithDependencies(Class<? extends T> type, Map<Class<?>, Object> beans) Instantiates an object of the given class performing dependency injections through the constructor.
-
Constructor Details
-
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 bag of objects to instantiate- Returns:
- the new instance
- Throws:
RuntimeException- if something fails- Since:
- 3.2-ALPHA-17
-
injectDependencies
Performs dependency injection to an object by means of field introspection.- Parameters:
object- the objectbeans- the bag of objects to instantiate- Since:
- 3.2-ALPHA-17
-
getClass
Returns the class literal associated to the given type.- Parameters:
type- the type to inspect- Returns:
- the class literal; it might be
nullif fails
-