Created
February 19, 2013 13:35
-
-
Save xeno-by/4985929 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 scala.reflect.runtime.universe._ | |
import scala.reflect.runtime.{currentMirror => cm} | |
trait Base { | |
def companion: MetaBase = { | |
val classSymbol = cm.classSymbol(getClass) | |
val moduleSymbol = classSymbol.companionSymbol.asModule | |
val moduleMirror = cm.reflectModule(moduleSymbol) | |
moduleMirror.instance.asInstanceOf[MetaBase] | |
} | |
} | |
trait MetaBase { | |
// stuff | |
} | |
object Test extends App { | |
class Foo extends Base | |
object Foo extends MetaBase | |
println(new Foo().companion) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment