内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/12901823/any-way-to-obtain-a-java-class-from-a-scala-2-10-type-tag-or-symbol
看起来这让我很近,但(a)不完全(见下文),(b)使用字符串表示的名字感觉像一个黑客…
scala> import scala.reflect.runtime.universe._import scala.reflect.runtime.universe._
scala> val t = typeOf[Int]
t: reflect.runtime.universe.Type = Int
scala> t.typeSymbol.asClass.fullName
res0: String = scala.Int
scala> object X { class Y }
defined module X
scala> val y = typeOf[X.Y]
y: reflect.runtime.universe.Type = X.Y
scala> Class.forName(y.typeSymbol.asClass.fullName)
java.lang.ClassNotFoundException: X.Y [...]
我是否缺少一些更直接的访问此信息的方法?或者是最好的,如果我还需要一些类的信息,只是为了保持 Java 类信息的并行集合? (啊!)
接收java.lang.Class或使用反射实例化对象必须使用镜像而不是类型和符号来完成,这些是Scala的编译时间信息:
scala> val m = runtimeMirror(getClass.getClassLoader) m: reflect.runtime.universe.Mirror = JavaMirror with ... scala> m.runtimeClass(typeOf[X.Y].typeSymbol.asClass) res25: Class[_] = class X$Y
代码日志版权声明:
翻译自:http://stackoverflow.com/questions/12901823/any-way-to-obtain-a-java-class-from-a-scala-2-10-type-tag-or-symbol
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- macos – dyld:惰性符号绑定失败:未找到符号:_PQsetErrorContextVisibility
- 嵌入式C语言自我修养 09:链接过程中的强符号和弱符号
- Scala中的符号
- “Bug-O” 符号
- 简单理解符号执行技术
- GCC 符号表小结
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
An Introduction to Genetic Algorithms
Melanie Mitchell / MIT Press / 1998-2-6 / USD 45.00
Genetic algorithms have been used in science and engineering as adaptive algorithms for solving practical problems and as computational models of natural evolutionary systems. This brief, accessible i......一起来看看 《An Introduction to Genetic Algorithms》 这本书的介绍吧!