static DuckTypedPSKKeyManager getInstance(Object obj) throws NoSuchMethodException {
        Class<?> sourceClass = obj.getClass();
        for (Method targetMethod : PSKKeyManager.class.getMethods()) {
            if (targetMethod.isSynthetic()) {
                continue;
            }
            // Check that obj exposes the target method (same name and parameter types)
            Method sourceMethod =
                    sourceClass.getMethod(targetMethod.getName(), targetMethod.getParameterTypes());
            // Check that the return type of obj's method matches the target method.
            Class<?> sourceReturnType = sourceMethod.getReturnType();
            Class<?> targetReturnType = targetMethod.getReturnType();
            if (!targetReturnType.isAssignableFrom(sourceReturnType)) {
                throw new NoSuchMethodException(sourceMethod + " return value (" + sourceReturnType
                        + ") incompatible with target return value (" + targetReturnType + ")");
            }
        }

        return new DuckTypedPSKKeyManager(obj);
    }
Gets an instance of {@code DuckTypedPSKKeyManager} which delegates all invocations of methods
of the {@link PSKKeyManager} interface to the same methods of the provided object.

@throws NoSuchMethodException if {@code obj} does not implement a method of the
        {@code PSKKeyManager} interface.
common/src/main/java/org/conscrypt/DuckTypedPSKKeyManager.java