scala 2.12 trait中丢失的注释信息



刚刚更新了一个scala 2.11 + JavaFX项目到2.12.0-RC1,代码大量使用java @FXML注释,例如

trait MainController {
  @FXML def onRun(event: ActionEvent) {
    val script = currentEngine.executeScript("editor.getValue()").toString
    runScript(script)
  }
}
<MenuItem mnemonicParsing="false" onAction="#onRun" text="Run">
   <accelerator>
        <KeyCodeCombination alt="UP" code="R" control="UP" meta="UP" shift="UP" shortcut="DOWN"/>
   </accelerator>
</MenuItem>

运行时执行FXMLLoader.load时抛出错误:

javafx.fxml.LoadException: Error resolving onAction='#onRun', either the event handler is not in the Namespace or there is an error in the script.

似乎在编译过程中丢失了@FXML注释信息。我听说在2.12中所有的特性都被编译成接口,但是这个变化是如何引起问题的呢?有什么变通办法吗?

虽然原因尚不清楚,但这个问题已经在scala-2.12.0-RC2中解决了。谢谢Scala团队。

最新更新