Created
October 28, 2015 17:03
-
-
Save longshorej/1a0a2cf50de8e6ff101c to your computer and use it in GitHub Desktop.
scala find all objects that subclass a case class or trait
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sbt dependencies: shapeless and org.reflections.reflections | |
val reflections = new Reflections("org.example") | |
def findAllObjects[T](cl: Class[T])(implicit t: Typeable[T]): Vector[T] = { | |
reflections.getSubTypesOf(cl).toVector.flatMap(cl => cl.getField("MODULE$").get(null).cast[T]) | |
} | |
findAllObjects(classOf[com.hpn.wms2.core.common.ClientDef]).foreach(println) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment