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. For example:
def convert(doc: ClickDoc): ClickVO = doc match {
case null => null
case _ =>
val result = new ClickVO
result.x = doc.x
result.y = doc.y
result
}
Now I sometimes need to convert a list of objects. How would I do this - I tried:
def convert[D <: MyBaseDoc, 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!