I wrote a method that gets a trait type as an input.
This is the trait Localizable:
import com.vividsolutions.jts.geom.Coordinate
trait Localizable {
val location : Coordinate
}
This is the method:
def localizeWithId(rdd : RDD[Localizable]) : RDD[(BigInt,Localizable)] = {
return rdd.map { case place =>
(getIdFromLocation(place.location.x, place.location.y), place)
}
}
The issue is that when I try to call this method, and send a case class that extends this trait as a parameter, I get an error of type mismatch.
This is the case class:
case class At (
eventDate : DateTime,
location : Coordinate
) extends Localizable
and this is the call:
val ats : RDD[At] = ...
val atsLocalized : RDD[(BigInt, At)] = localizeWithId(ats)
How can I solve it? Thanks.
RDD[(BigInt, At)]while actual return type isRDD[(BigInt,Localizable)]which is type mismatch, exacly what you get. Solution might be to definedef localizeWithId[A <: Localizable](rdd: RDD[A]): RDD[(BigInt, A)]- Łukasz