Вот связанный фрагмент кода. PrettyPrint-Override ">
Код: Выделить всё
public class InputController {
public void handleFileSelection(ActionEvent actionEvent){
//event handling code
}
public InputController() {
//init controller
}
}
Код: Выделить всё
InputController inputController = new InputController();
fileButton.setOnAction(inputController::handleFileSelection);
val inputController = new InputController
fileButton.setOnAction(inputController::handleFileSelection)
< /code>
Вот сообщение об ошибке от компилятора (Scala 2.11.6). < /p>
Error:(125, 45) missing arguments for method handleFileSelection in class Main;
follow this method with '_' if you want to treat it as a partially applied function
fileButton.setOnAction(inputController::handleFileSelection)
^
< /code>
Если я использую Scala 2.12.0-M2 вместо этого, я получаю другое сообщение об ошибке.Error:(125, 45) missing argument list for method handleFileSelection in class Main
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `handleFileSelection _` or `handleFileSelection(_)` instead of `handleFileSelection`.
fileButton.setOnAction(inputController::handleFileSelection)
^
< /code>
Есть ли нативный способ, какой Scala может использовать ссылки на метод, представленные в Java 8? Мне известно о подходе неявных конверсий для использования выражения лямбды, но я хочу знать, есть ли способ использовать ссылку на метод, аналогичный Java 8 без необходимости использования декларации Lambda.
Подробнее здесь: https://stackoverflow.com/questions/319 ... s-in-scala