根據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,...) –