private static MethodHandle findCtorMethodHandleForParameters(Class<?> type, Class<?>... types) {
        Deque<Throwable> suppressedThrowables = new ArrayDeque<>();

        var constructors = type.getConstructors();

        for (int argCount = types.length; argCount >= 0; argCount--) {
            tryNextConstructor:
            for (var constructor : constructors) {
                if (constructor.getParameterCount() != argCount) {
                    continue;
                }

                for (int i = 0; i < argCount; i++) {
                    if (!constructor.getParameterTypes()[i].isAssignableFrom(types[i])) {
                        continue tryNextConstructor;
                    }
                }

                try {
                    var methodHandle = MethodHandles.lookup().unreflectConstructor(constructor);
                    if (argCount < types.length) {
                        // the method handle will always be called with all possible arguments.
                        // Using dropArguments will remove any argument that the method handle not
                        // need (because the actual c'tor takes less arguments). This allows calling invokeExact because
                        // the exposed method handle will always take all arguments.
                        methodHandle = MethodHandles.dropArguments(methodHandle, argCount,
                                Arrays.copyOfRange(types, argCount, types.length));
                    }
                    return methodHandle.asType(methodHandle.type().changeReturnType(Object.class));
                } catch (IllegalAccessException e) {
                    suppressedThrowables.add(e);
                }
            }
        }

        var failure = new NoSuchMethodException(format("No constructor for class '%s', loosely matching arguments %s", type.getName(), Arrays.toString(types)));
        suppressedThrowables.forEach(failure::addSuppressed);

        // return a method handle that will throw the no such method exception on invocation, thus deferring
        // the actual exception until invocation time.
        return MethodHandles.dropArguments(
                MethodHandles.insertArguments(MethodHandles.throwException(Object.class, Exception.class), 0, failure),
                0, types);
    }
Inspect a type and find a matching constructor. The method tries to match as many parameters as possible
to the available constructors, cutting off parameters from the end one-by-one until a matching constructor is found.

@param type  The type that should be instantiated.
@param types Array of parameter types.
@return a handle to the found constructor, with the argument list adjusted to drop excess parameters
core/src/main/java/org/jdbi/v3/core/internal/JdbiClassUtils.java