1

I am try to create map with different map inside

val mymap = Map("name"->"somename",Map(1->2))

I got from compiler:

scala: type mismatch;
 found   : scala.collection.immutable.Map[Int,Int]
 required: (?, ?)
  val mymap = Map("name"->"somename",Map(1->2))
                                        ^
1
  • Presumably you need some key for your nested Map which is the value... Commented Jul 11, 2013 at 15:27

2 Answers 2

4

Why do you expect it to work? You've provided only key without value:

val key = Map(1->2)
val mymap = Map("name"->"somename", key)

Perhaps you wanted to combine two maps? This can be done with:

val mymap = Map("name"->"somename") ++ Map(1->2)
// scala.collection.immutable.Map[Any,Any] = Map(name -> somename, 1 -> 2)
Sign up to request clarification or add additional context in comments.

Comments

3

A Map consists of key-value pairs (whose type is (?, ?)). You have to assign the Map value to a key as well:

val mymap = Map("name"->"somename","othername"->Map(1->2))

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.