有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaFXJava方法句柄

@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);

}

为什么我会犯这个错误

爪哇。lang.invoke。ErrorMethodTypeException:无法将MethodHandle(HomePresenter、ListIterator、Text)void转换为(ListIterator、Text)void


共 (1) 个答案

  1. # 1 楼答案

    看看MethodHandle中的示例——我认为您需要将要调用该方法的实例作为第一个参数传递

    leftButtonClickMethod.invoke(this,list, menuTitle);
    

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