private static <T> Object notConfigField(Class<T> clazz, List<Object> instances, Set<Class<?>> allInjectableTypes, Parameter param) {
        final Class<?> paramType = param.getType();
        final Optional<? extends Class<?>> injectKeyClass = traverseAncestors(paramType)
            .filter(c -> c.isAnnotationPresent(InjectKey.class))
            .map(c -> c.getAnnotation(InjectKey.class).value())
            .findFirst();
        if (injectKeyClass.isPresent()) {
            // Make sure that there are no other pending instances that
            // may implement this type, see #758
            //
            // This set contains all classes that we need to be instantiated
            // before we know which one to select
            final Set<Class<?>> needed = allInjectableTypes.stream()
                .filter(c -> traverseAncestors(c)
                    .anyMatch(a -> a.isAnnotationPresent(InjectKey.class) && a.getAnnotation(InjectKey.class).value().equals(injectKeyClass.get()))
                )
                .collect(toSet());

            // Remove the existing classes
            instances.stream()
                .map(Object::getClass)
                .forEach(needed::remove);

            if (!needed.isEmpty()) {
                // We do not know all instances yet so we have to wait for
                // their creation
                return null;
            }
        }

        final Optional<Object> value = instances.stream()
            .filter(o -> paramType.isAssignableFrom(o.getClass()))
            .findFirst();

        if (value.isPresent()) {
            return value.get();
        } else {
            throw new IllegalArgumentException(String.format("No instance found that match the required type '%s' in the constructor for injected class '%s'.", param.getClass().getName(), clazz.getName()));
        }
    }
Some common utility methods for analyzing classes with reflection.

@author Emil Forslund
@since 1.0.0
common-parent/injector/src/main/java/com/speedment/common/injector/internal/util/ReflectionUtil.java