Skip to content

@xeno-by /gist:4985929
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.