Skip to content

Instantly share code, notes, and snippets.

@retronym
Created August 21, 2012 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retronym/3416688 to your computer and use it in GitHub Desktop.
Save retronym/3416688 to your computer and use it in GitHub Desktop.
Casting from reflect.api to reflect.internal
scala> val m = reflect.runtime.currentMirror
m: reflect.runtime.universe.Mirror = JavaMirror with scala.tools.nsc.interpreter.IMain$TranslatingClassLoader@69af0fcf of type class scala.tools.nsc.interpreter.IMain$TranslatingClassLoader with classpath [(memory)] and parent being scala.tools.nsc.util.ScalaClassLoader$URLClassLoader@6437153d of type class scala.tools.nsc.util.ScalaClassLoader$URLClassLoader with classpath [file:/c:/tools/jdk1.6.0_25/jre/lib/resources.jar,file:/c:/tools/jdk1.6.0_25/jre/lib/rt.jar,file:/c:/tools/jdk1.6.0_25/jre/lib/jsse.jar,file:/c:/tools/jdk1.6.0_25/jre/lib/jce.jar,file:/c:/tools/jdk1.6.0_25/jre/lib/charsets.jar,file:/c:/tools/jdk1.6.0_25/jre/lib/ext/dnsns.jar,file:/c:/tools/jdk1.6.0_25/jre/lib/ext/localedata.jar,file:/c:/tools/jdk1.6.0_25/jre/lib/ext/sunjce_provider.jar,file:/C:/tools/SCALA-~1.0-M/bin...
scala> val u = reflect.runtime.currentMirror.universe
u: reflect.runtime.universe.type = scala.reflect.runtime.JavaUniverse@6221a86a
scala> val s: reflect.internal.SymbolTable = null // just a dummy prefix
s: scala.reflect.internal.SymbolTable = null
scala> val int = u.typeOf[Int]; val float = u.typeOf[Float]
int: u.Type = Int
float: u.Type = Float
scala> int weak_<:< float
<console>:11: error: value weak_<:< is not a member of u.Type
int weak_<:< float
^
scala> int.asInstanceOf[s.Type] weak_<:< float.asInstanceOf[s.Type]
res13: Boolean = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment