I want to create a map, where each key pairs with a value that has its own type. However, it throws a run time error scala.MatchError: Property[_] (of class scala.reflect.internal.Types$ExistentialType)
Anyone knows why? my guess is the scala type erasure?
case class Property[T: ClassTag](val value: T)
case class PropertyList(d: Map[String, Property[_]]) {
def get[A: ClassTag](name: String): Option[A] =
d.get(name)
.flatMap { p =>
p.value match {
case o: A => Some(o)
case _ => None
}
}
}
case class myObject (
propertyList: PropertyList =
PropertyList(Map.empty[String, Property[_]])
)
Aucun commentaire:
Enregistrer un commentaire