根据docs here,declarations
应该是members
的子集,用于类中声明的事物,不是继承的。那么为什么各个班级没有报告声明?为什么scala反射报告某些类没有声明?
scala> import scala.reflect.runtime.universe._
scala> typeTag[java.lang.System].tpe.declarations
res5: reflect.runtime.universe.MemberScope = SynchronizedOps()
类'java.lang.System'没有在Scala中的任何成员。这个帖子告诉你如何得到它:http://stackoverflow.com/questions/11020746/get-companion-object-instance-with-new-scala-reflection-api – gzm0
该代码抛出一个异常,如果我用'java.lang.System'尝试它,因为它查找'System $'。不清楚如何获得静态方法列表。 –
scala> typeOf [System] .typeSymbol.companionSymbol .typeSignature.declarations res5:reflect.runtime.universe.MemberScope = SynchronizedOps(value in,value out,value err,...) –