鉴于此代码:
MethodType mt = MethodType.methodType(void.class, DomainObject.class);
NOOP_METHOD = RULE_METHOD_LOOKUP.findVirtual(RulesEngine.class, "noOpRule", mt);
产生的 NOOP_METHOD 是
MethodHandle(RulesEngine,DomainObject)void
为什么第一个参数在那里,当我调用它时会导致失败,比如
mh.invoke(domainObject);
因为错误消息是:
java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(RulesEngine,DomainObject)void to (DomainObject)void
这是有问题的方法:
public void noOpRule(DomainObject d) {
}