In Scala I have the code that I am writing Map[String, AnyRef]. When I try to initialize the map using the following, Scala complains that it expects Map[String, AnyRef], but the value is Map[String, Any]:
val myMap: Map[String, AnyRef] =
Map("foo" -> true, "bar" -> false)
I know that I can use the following instead:
val myMap: Map[String, AnyRef] =
Map("foo" -> true.asInstanceOf[AnyRef], "bar" -> false.asInstanceOf[AnyRef])
I declared the following in the area:
implicit def booleanToAnyRef(value: Boolean): AnyRef = value.asInstanceOf[AnyRef]
but the compiler is still complaining.
Should the compiler use an implicit method to convert primitive boolean values to values AnyRef? Is there any way (ugly) x.asInstanceOf[AnyRef]to convert this data?
Ralph source
share