1

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 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.