Is it possible to use a Java 8 style method references in Scala?

后端 未结 3 1160
小蘑菇
小蘑菇 2020-12-05 18:12

I\'m developing a JavaFX8 application in Scala but I couldn\'t figure out how to pass a method reference to an event handler. To clarify, I\'m not using ScalaFX library but

3条回答
  •  清歌不尽
    2020-12-05 18:32

    If you want a method reference that also takes the class instance as a parameter, for instance like String::length in Java, you can do (_:String).length which is equivalent to (s:String) => s.length().

    The types of these are in Java Function and in Scala thus String => Int.

提交回复
热议问题