Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Map to Java HashMap

I have a Scala function f(s1: String, s2: String): Map[String,String]

I want to allow a colleague coding in Java to call a Java method I'm writing:

HashMap<String, String> f(String s1, String s2)

This calls my Scala function. What I've found, on the Java side, is that Scala has returned a scala.collection.immutable.Map.

How do I make a Java HashMap out of it? Or should I be doing something else?

like image 472
gknauth Avatar asked Apr 28 '14 20:04

gknauth


1 Answers

I think what you are looking for is here. Specifically the mapAsJavaMap method.

Where the preferred usage is explained in this SO question Using imported implicits and asJava

like image 189
Justin Pihony Avatar answered Nov 12 '22 07:11

Justin Pihony