Package org.axonframework.common
Class ConstructorUtils
java.lang.Object
org.axonframework.common.ConstructorUtils
Utility class for constructing objects using reflection.
Utility functions in this class do not create instances directly. Instead, they provide reusable functions that can be used to construct a multitude of instances of the same type. It is advisable to cache this function for reuse.
- Since:
- 5.0.0
- Author:
- Mitchell Herrijgers
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,A> Function <A, T> factoryForTypeWithOptionalArgument(Class<T> type, Class<? extends A> argumentClass) Returns a function that constructs an instance of the given type using the constructor that accepts an argument of the given class, or alternatively using a zero-argument constructor.static <T> Supplier<T> Returns a function that constructs an instance of the given type using the zero-argument constructor.
-
Method Details
-
getConstructorFunctionWithZeroArguments
Returns a function that constructs an instance of the given type using the zero-argument constructor. If the type does not have a zero-argument constructor, anIllegalArgumentExceptionis thrown.- Type Parameters:
T- The type of object to construct.- Parameters:
type- The type of object to construct. Must have a zero-argument constructor.- Returns:
- A function that constructs an instance of the given type using the zero-argument constructor.
-
factoryForTypeWithOptionalArgument
public static <T,A> Function<A,T> factoryForTypeWithOptionalArgument(@Nonnull Class<T> type, @Nonnull Class<? extends A> argumentClass) Returns a function that constructs an instance of the given type using the constructor that accepts an argument of the given class, or alternatively using a zero-argument constructor. If neither is available, anIllegalArgumentExceptionis thrown.- Type Parameters:
T- The type of object to construct.A- The type of the argument to pass to the constructor.- Parameters:
type- The type of object to construct. Must have a constructor that accepts an argument of the given class, or a zero-argument constructor.argumentClass- The class of the argument to pass to the constructor.- Returns:
- A function that constructs an instance of the given type using the constructor that accepts an argument of the given class, or alternatively using a zero-argument constructor.
-