Class ConstructorInstantiator
- All Implemented Interfaces:
Instantiator
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object[]private final booleanWhether or not the constructors used for creating an object refer to an outer instance or not. -
Constructor Summary
ConstructorsConstructorDescriptionConstructorInstantiator(boolean hasOuterClassInstance, Object... constructorArgs) -
Method Summary
Modifier and TypeMethodDescriptionprivate Stringprivate Stringprivate voidevaluateConstructor(List<Constructor<?>> matchingConstructors, Constructor<?> constructor) Evalutesconstructoragainst the currently foundmatchingConstructorsand determines if it's a better match to the given arguments, a worse match, or an equivalently good match.private static <T> TinvokeConstructor(Constructor<?> constructor, Object... params) private InstantiationExceptionmultipleMatchingConstructors(Class<?> cls, List<Constructor<?>> constructors) <T> TnewInstance(Class<T> cls) Creates instance of given classprivate InstantiationExceptionnoMatchingConstructor(Class<?> cls) private InstantiationExceptionparamsException(Class<?> cls, Exception e) private static booleanparamsMatch(Class<?>[] types, Object[] params) private <T> TwithParams(Class<T> cls, Object... params)
-
Field Details
-
hasOuterClassInstance
private final boolean hasOuterClassInstanceWhether or not the constructors used for creating an object refer to an outer instance or not. This member is only used to for constructing error messages. If an outer inject exists, it would be the first ([0]) element of theconstructorArgsarray. -
constructorArgs
-
-
Constructor Details
-
ConstructorInstantiator
-
-
Method Details
-
newInstance
Description copied from interface:InstantiatorCreates instance of given class- Specified by:
newInstancein interfaceInstantiator
-
withParams
-
invokeConstructor
private static <T> T invokeConstructor(Constructor<?> constructor, Object... params) throws InstantiationException, IllegalAccessException, InvocationTargetException -
paramsException
-
constructorArgTypes
-
noMatchingConstructor
-
constructorArgsString
-
multipleMatchingConstructors
private InstantiationException multipleMatchingConstructors(Class<?> cls, List<Constructor<?>> constructors) -
paramsMatch
-
evaluateConstructor
private void evaluateConstructor(List<Constructor<?>> matchingConstructors, Constructor<?> constructor) Evalutesconstructoragainst the currently foundmatchingConstructorsand determines if it's a better match to the given arguments, a worse match, or an equivalently good match.This method tries to emulate the behavior specified in JLS 15.12.2. Compile-Time Step 2: Determine Method Signature. A constructor X is deemed to be a better match than constructor Y to the given argument list if they are both applicable, constructor X has at least one parameter than is more specific than the corresponding parameter of constructor Y, and constructor Y has no parameter than is more specific than the corresponding parameter in constructor X.
If
constructoris a better match than the constructors in thematchingConstructorslist, the list is cleared, and it's added to the list as a singular best matching constructor (so far).
Ifconstructoris an equivalently good of a match as the constructors in thematchingConstructorslist, it's added to the list.
Ifconstructoris a worse match than the constructors in thematchingConstructorslist, the list will remain unchanged.- Parameters:
matchingConstructors- A list of equivalently best matching constructors found so farconstructor- The constructor to be evaluated against this list
-