I wonder how can I preserve my type constraints while trying to workaround over 'Covariant type parameter in a wrong position problem' situation. Here is the code:
trait Converter[SourceType, +JobType <: ConverterJobType[SourceType]] {
def convert[JT >: JobType](job: JT):String = job.someMethodFromJobType()// method is not accessible here. I would like to use JobType but actually job is treated like type Any.
}
object Converter{
implicit object CSVConverter extends Converter[CSV, CSVConverterJobType]{
def converter....
}
}
I need covariance so that my implicit object could be looked up.
case class CSVConverterJobType(...) extends ConverterJobType[SourceType]
object Application {
def process[T](job: List[T])(implicit
converter:Converter[T,ConverterJobType[T]]) = {...}
val list:List[CSV] = ...
process(list)
}
In order to process
method to be able to find implicit.... I need to make second type parameter covariant. But then I'm not able to use actual type information in convert
method.
Any idea how to overcome this?