Home>

The function of the event when the value of TextField of javaFX generated in the class created in Java8 environment is changed is registered by addListener anonymously.
I want to refer to this TextField in another class and replace it with a function that performs another process in that class, so I want to remove the anonymous function once with removeListener. Is it better to specify it?

class Hoge {
  void hogeMethod (TextField inputObj) {
    inputObj.textProperty (). addListener ((ObservableValue<? extends String>observableValue, String s, String s2)->{
        // Processing after change (I want to change this content with a method of another class)
    });
  }
}

I was hoping to get a function pointer that was addListener, but I searched for such a method, but I couldn't find any useful information on the net.

It seems that it can be realized by storing the anonymous function in UserData of TextField and referencing it, but if there is any smarter method, please let me know.