Thursday, 15 August 2013

Scala List with only subclasses

Scala List with only subclasses

Is there a way to have a List["only subclasses of DataElement"] or
List["only with trait Element"]?
I thought it could be like this
val test: List[_ <: DataElement] = List(DataElement("hi"), DataMessage("ho"))
with DataMessage extends DataElement
But i get this error
type mismatch; found : DataMessage.type required: DataElement

No comments:

Post a Comment