@SuppressWarnings("unchecked")
    private static <T> Optional<Constructor<T>> findConstructor(Class<T> clazz, List<Object> instances, Set<Class<?>> allInjectableTypes) {
        // If at least one constructor has the @Inject-annotation, only
        // @Inject-annotated constructors should be considered.
        return Arrays.stream(clazz.getDeclaredConstructors())
            .sorted(Comparator.comparing(constr -> constr.isAnnotationPresent(Inject.class) ? 1 : 0))
            .filter(constr -> isOnlyIfMissingConditionSatisfied(constr, allInjectableTypes))
            .filter(constr -> canBeInvoked(constr, instances))
            .map(constr -> (Constructor<T>) constr)
            .findFirst();
    }
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