Created
October 17, 2014 18:56
-
-
Save clhodapp/5c8bf5a0fe96e534a302 to your computer and use it in GitHub Desktop.
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
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