Skip to content

Instantly share code, notes, and snippets.

@Sciss
Last active December 18, 2015 02:48
Show Gist options
  • Select an option

  • Save Sciss/5713325 to your computer and use it in GitHub Desktop.

Select an option

Save Sciss/5713325 to your computer and use it in GitHub Desktop.
import reflect.runtime.{universe => ru}
val m = ru.runtimeMirror(getClass.getClassLoader)
case class Bar(i: Int)
val tpe = ru.typeOf[Bar]
val classBar = tpe.typeSymbol.asClass
val cm = m.reflectClass(classBar)
val ctor = tpe.declaration(ru.nme.CONSTRUCTOR).asMethod
val ctorm = cm.reflectConstructor(ctor)
val p = ctorm(33)
// figuring out arg types
val arg1 = ctor.paramss.head.head
arg1.typeSignature =:= ru.typeOf[Int] // true. is there a simpler way?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment