I'm writing some scalafx
code, which needs to invoke a method from java:
val txtEditor = new TextArea {
text = "markdown here"
}
txtEditor.text.addListener(new ChangeListener[String] {
override def stateChanged(e: ChangeEvent): Unit = ???
})
But it reports compilation error on the addListener
parameter:
Type mismatch, expected: ChangeListener[_ >: String], actual: ChangeListener with Object { def stateChange(e:ChangeEvent) Unit }
And the addListener
which is a java method:
void addListener(ChangeListener<? super T> listener);
How to fix it?
FTR, to answer the question title.
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]