0

In scala i have function like this:

def generateString(format: String, 
    parameters: Map[String, String] = Map()) {

    generate(format, parameters)    
}

And now, i want to call it form java

Map<String, String> params = new HashMap<String, String>();
params.put("test1", "test2");
Generator.generateString("", params);

But i get error that cannot convert form java map to scala map.

So, how to solve this.

p.s. I am new to Scala.

1

1 Answer 1

1

Change your utility signature:

def generateString(format: String, 
    parameters: java.util.Map[String, String] = new java.util.HashMap()) {

Or use java-to-scala converter in Java code:

Generator.generateString("", scala.collection.JavaConversions.mapAsScalaMap(params));
Sign up to request clarification or add additional context in comments.

1 Comment

For first solution i get error: - object java.util.HashMap is not a value

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.