Skip to content

Instantly share code, notes, and snippets.

@jianyuan
Forked from piotrga/gist:5928581
Last active January 10, 2016 11:32
Show Gist options
  • Save jianyuan/3200c953e10d1329ed44 to your computer and use it in GitHub Desktop.
Save jianyuan/3200c953e10d1329ed44 to your computer and use it in GitHub Desktop.
Scala 2.10 ReflectionSugars
trait ReflectionSugars{
import scala.reflect.runtime.{universe => ru}
private lazy val universeMirror = ru.runtimeMirror(getClass.getClassLoader)
def companionOf[T](implicit tt: ru.TypeTag[T]) = {
val companionMirror = universeMirror.reflectModule(ru.typeOf[T].typeSymbol.companionSymbol.asModule)
companionMirror.instance
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment