private static MethodHandle asMethodHandle(Method method, @Nullable Object object) {
        MethodHandle methodHandle;
        try {
            // an investigation showed no difference in performance between the MethodHandle
            // obtained via either MethodHandles.Lookup#unreflect or MethodHandles.Lookup#findVirtual
            methodHandle = lookup.unreflect(method);
        } catch (IllegalAccessException e) {
            // this is extremely unlikely considering that we've already executed method.setAccessible(true)
            throw new RuntimeException(e);
        }
        if (!Modifier.isStatic(method.getModifiers())) {
            // bind non-static methods to an instance of the declaring class
            methodHandle = methodHandle.bindTo(requireNonNull(object, "object"));
        }
        final int parameterCount = method.getParameterCount();
        // allows MethodHandle accepting an Object[] argument and
        // spreading its elements as positional arguments
        return methodHandle.asSpreader(Object[].class, parameterCount);
    }
Converts {@link Method} to {@link MethodHandle}, optionally accepting {@code object} instance of the
declaring class in case of non-static methods. Result {@link MethodHandle} must be assigned to
a {@code final} field in order to enable Java compiler optimizations.
@param method the {@link Method} to be converted to a {@link MethodHandle}
@param object an instance of declaring class for non-static methods, or {@link null} for static methods
@return a {@link MethodHandle} corresponding to the supplied {@link Method}
core/src/main/java/com/linecorp/armeria/internal/server/annotation/DefaultAnnotatedService.java