我试图延长javax.swing.Timer中不被认可,但它只有一个构造函数,它是斯卡拉 - 方法构造
Timer(int delay, ActionListener listener)
我不希望我在斯卡拉子取一个Java ActionListener
在它的构造函数中。我在very old thread中读到:“没有办法直接调用超类的构造函数;你必须传递你自己类的主构造函数”,所以它看起来像我坚持在主构造函数中使用ActionListener
。所以我增加了一个辅助构造这样的:
case class TimerEvent (source: AnyRef) extends swing.event.Event
class ScalaTimer2 (delay: Int, listener: java.awt.event.ActionListener)
extends javax.swing.Timer(delay, listener) with swing.Publisher {
outer =>
def this(delay: Int) = {
this(delay, new java.awt.event.ActionListener {
def actionPerformed(e: java.awt.event.ActionEvent) {
publish(TimerEvent(outer)) // <-- publish not recogonized
}
})
// publish(TimerEvent(outer)) // <-- publish recognized here
}
}
不过,我得到一个编译错误error: not found: value publish
...为什么?以及如何解决?
对于那些寻找到这个问题,意识到问题的SI-4842,其崩溃的编译器:https://issues.scala-lang.org/browse/SI-4842 –