Question

If I write:

class T
implicit val m = Map[String, Map[T, Int]]()
"123"(0)

it complains with:

<console>:10: error: type mismatch;
  found   : Int(0)
  required: T
          "123"(0)

But it should return '1'. All that I understand is that not only m is implicit, but also m.apply. Why is it so ?

Was it helpful?

Solution

Map[A,B] is a A => B, so scala converts your string to your Map[T, Int].

This has been complained about on the MLs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top