0
@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
    Can you post the relevant code from `HomePresenter`? It's hard for me to see why you are using this kind of reflective approach to invoke the method instead of just calling it in the usual way. – James_D Nov 19 '14 at 15:51

1 Answers1

0

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.

tomsontom
  • 5,856
  • 2
  • 23
  • 21