Here's some code which looks reasonable enough to me:
val myMap: Map[Int, Int] = ((x: Int) => Map[Int, Int](1 -> x + 1, 2 -> x + 2))(4)
When I try to compile it, I get two errors like this:
Error:(20, 68) type mismatch;
found : Int(1)
required: String
val myMap: Map[Int, Int] = ((x: Int) => Map[Int, Int](1 -> x + 1, 2 -> x + 2))(4)
^
I understand that my compiler is trying to use the string addition implementation of +
. But why is it doing that? How do I ask the compiler to use integer addition here?
(Changing Int
to Integer
doesn't help.)