Skip to content

Instantly share code, notes, and snippets.

@clhodapp
Created October 17, 2014 18:56
Show Gist options
  • Save clhodapp/5c8bf5a0fe96e534a302 to your computer and use it in GitHub Desktop.
Save clhodapp/5c8bf5a0fe96e534a302 to your computer and use it in GitHub Desktop.
import reflect.runtime.universe._
import reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox
class Demo[T: TypeTag] {
def runTest(): Any = {
val tb = currentMirror.mkToolBox()
val companion = typeOf[T].typeSymbol.companion
tb.eval(q"$companion.test")
}
}
object X {
class Foo
object Foo { def test = 1 }
class Bar
object Bar { def test = "abc" }
}
new Demo[X.Foo].runTest
new Demo[X.Bar].runTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment