1
votes

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?

1
ChangeListener as per docs.oracle.com/javafx/2/api/javafx/beans/value/… is different from what you have used. Can you mention teh api link for your ChangeLsitener?Jatin
Are you looking at Swing's class instead?som-snytt
Sorry, I used a wrong ChangeListener :(Freewind

1 Answers

1
votes

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]