我正在尝试设计几个继承部分函数的类,但我似乎无法完全正确地获得语法。我的超类看起来像这样:
abstract class Controller {
val react:PartialFunction[Event,Unit]
}
子类看起来像:
class BoardRendererController(val renderer:BoardRenderer, val board:Board) extends Controller {
override val react {
case PieceMovedEvent(piece, origin, destination) => println("Moving now")
}
}
但这无法编译并出现此错误
[ERROR] /workspace/pacman/src/main/scala/net/ceilingfish/pacman/BoardRendererController.scala:14: error: '=' expected but '{' found.
[INFO] override val react {
[INFO] ^
[ERROR] /workspace/pacman/src/main/scala/net/ceilingfish/pacman/BoardRendererController.scala:17: error: illegal start of simple expression
[INFO] }
[INFO] ^
我已经尝试了很多变体,有人知道正确的语法是什么吗?