I migrate some scala code from 2.12 to 2.13 and I have the following code
def getMetrics(): java.util.Map[String, Double] ={
transformers.map{
case transformer => transformer match{
case t: EvaluationTransformFunction => t.getMetric.asJava
}
}.flatten.toMap.asJava
}
that produces the error
error: No implicit view available from java.util.Map[String,Double] => scala.collection.IterableOnce[B].
[ERROR] }.flatten.toMap.asJava
[ERROR] ^
can you explain what is the error about?
We're missing a bit more info about the exact types you are manipulating but the idea is that:
transformers.map(...)is aIterable[SomeJavaCollectionType]flattenworks only ifSomeJavaCollectionTypecan be "transformers/"viewed" as aIterable[SomeOtherType]so thatIterable[SomeJavaCollectionType]can be viewed asIterable[Iterable[SomeOtherType]]and thus flattenedSomeJavaCollectionTypewhich seems to beJavaMap[String, Double]if I read it correctlyI'm slightly surprised it was working in Scala 2.12. Maybe there's an
importthat would make it work in Scala 2.13 as well (i.e. bring the "implicit view" in scope).Anyway, I would just get rid of the inner
asJavaand only convert to Java collection at the end of your method: