我正在编写一些scalafx
代码,需要从java调用一个方法:
val txtEditor = new TextArea {
text = "markdown here"
}
txtEditor.text.addListener(new ChangeListener[String] {
override def stateChanged(e: ChangeEvent): Unit = ???
})
但它报告了addListener
参数的编译错误:
类型不匹配,预期:ChangeListener [_>:String], actual:ChangeListener with Object {def stateChange(e:ChangeEvent)Unit}
addListener
是一个java方法:
void addListener(ChangeListener<? super T> listener);
如何解决?
答案 0 :(得分:1)
FTR,回答问题标题。
scala> val is = (1 to 10).to[collection.mutable.LinkedList].asJava
warning: there were 2 deprecation warning(s); re-run with -deprecation for details
is: java.util.List[Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
scala> is sort (new java.util.Comparator[Int] { def compare(a: Int, b: Int) = b - a })
scala> is
res13: java.util.List[Int] = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]