How to explicitly invoke default method from a dynamic Proxy?

前端 未结 6 821
一向
一向 2020-12-09 15:33

Since Java 8 interfaces could have default methods. I know how to invoke the method explicitly from the implementing method, i.e. (see Explicitly calling a default method i

6条回答
  •  北海茫月
    2020-12-09 15:48

    Use:

    Object result = MethodHandles.lookup()
        .in(method.getDeclaringClass())
        .unreflectSpecial(method, method.getDeclaringClass())
        .bindTo(target)
        .invokeWithArguments();
    

提交回复
热议问题