I have a Scala case class and a corresponding Java class. I've declared an implicit conversion from Scala class to Java class. Now I have a Scala collection of Scala classes, and I want to convert them to Scala collection of Java classes. Is it possible with the implicit conversion? Here's what I've tried, naively perhaps:
case class PositionScala(latitude: Double, longitude: Double)
object PositionScala {
implicit def toJava(p: PositionScala): Position = new Position(p.latitude, p.longitude) // Position is the Java class
}
...
val p: List[Position] = routeScala.shape.map(p => p)
// routeScala.shape is List[PositionScala]
But it doesn't compile with the type mismatch error. Of course I can call the conversion function explicitly, but it defeats the purpose of using implicit converter. Is there a way to do what I want?