I'm quite new to Scala and struggling with the following:
I have database objects (type of BaseDoc) and value objects (type of BaseVO). Now there are multiple convert methods (all called 'convert') that take an instance of an object and convert it to the other type accordingly - like this:
def convert(doc: ClickDoc): ClickVO = ...
def convert(doc: PointDoc): PointVO = ...
def convert(doc: WindowDoc): WindowVO = ...
Now I sometimes need to convert a list of objects. How would I do this - I tried:
def convert[D <: BaseDoc, V <: BaseVO](docs: List[D]):List[V] = docs match {
case List() => List()
case xs => xs.map(doc => convert(doc))
}
Which results in 'overloaded method value convert with alternatives ...'. I tried to add manifest information to it, but couldn't make it work.
I couldn't even create one method for each because it'd say that they have the same parameter type after type erasure (List).
Ideas welcome!