1
votes

I often occur the problem that although I imported the scala.collection.JavaConverters._ converters into my scala file, the implicit conversion does not happen.

Assume the following code (where submissionStorage.get is some Java function returning a Java Map)

import scala.collection.JavaConverters._
import scala.collection.mutable

...

val submissions: java.util.Map[String, String] = submissionStorage.get(formname)
val submissionJavaKeys: java.util.Set[String] = submissions.keySet()
val submissionScalaKeys: mutable.Set[String] = submissionJavaKeys

Leds into the following compile error:

type mismatch; found : java.util.Set[String] required: scala.collection.mutable.Set[String]

Now the documentation of the JavaConverters states that there is a conversion "scala.collection.mutable.Set <=> java.util.Set", so exactlly what I need here.

What am I doing wrong, so under which conditions do the JavaConverters work?

1

1 Answers

4
votes

JavaConverters adds asJava and asScala methods. You want JavaConversions instead.