lundi 22 juin 2015

Get all object with particular trait in scala

Given this code:

trait A[T]{
  val name: String
  val inner: T
}

object B extends A[String]{
  val name = "objB"
  val inner = "5"
}

object C extends A[Int]{
  val name = "objC"
  val inner = 5
}

object D{
  val name = "objD"
}

I want to get all inheritors of trait A:

Map("objB" -> B, "objC" -> C)

Is it possible with reflection? Can this map be generated at compile time?





Aucun commentaire:

Enregistrer un commentaire