Java MethodHandle

131 views Asked by At
@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);

}

Why I get this error?

java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(HomePresenter,ListIterator,Text)void to (ListIterator,Text)void

1

There are 1 answers

0
tomsontom On

Looking at the example in MethodHandle - I think you need to pass the instance on which you want to call the method as the first argument

leftButtonClickMethod.invoke(this,list, menuTitle);

but because I never worked with java.lang.invoke this might be completely wrong.