Java方法句柄

Java方法句柄,java,javafx,methodhandle,Java,Javafx,Methodhandle,} 为什么我会犯这个错误 java.lang.invoke.ErrorMethodTypeException:无法将MethodHandleHomePresenter、ListIterator、Textvoid转换为ListIterator、Textvoid查看MethodHandle中的示例-我认为您需要将要调用该方法的实例作为第一个参数传递 @FXML private void handleLeftButton() throws Throwable{ MethodHandles.Looku

}

为什么我会犯这个错误


java.lang.invoke.ErrorMethodTypeException:无法将MethodHandleHomePresenter、ListIterator、Textvoid转换为ListIterator、Textvoid查看MethodHandle中的示例-我认为您需要将要调用该方法的实例作为第一个参数传递

@FXML private void handleLeftButton() throws Throwable{

MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodType methodType = MethodType.methodType(void.class, ListIterator.class, Text.class);
MethodHandle leftButtonClickMethod = lookup.findVirtual(HomePresenter.class, "leftButtonClick", methodType);

leftButtonClickMethod.invoke(list, menuTitle);

但是,因为我从未使用过java.lang.invoke,这可能是完全错误的。

你能从HomePresenter发布相关代码吗?我很难理解为什么要使用这种反射方法来调用该方法,而不是用通常的方式调用它。
leftButtonClickMethod.invoke(this,list, menuTitle);