Rob N
Rob N

Reputation: 16419

Why is scala reflection reporting no declarations for certain classes?

According to the docs here, declarations should be a subset of members for the things declared in the class, not inherited. Then why do various classes report no declarations?

scala> import scala.reflect.runtime.universe._
scala> typeTag[java.lang.System].tpe.declarations
res5: reflect.runtime.universe.MemberScope = SynchronizedOps()

Upvotes: 1

Views: 94

Answers (1)

subsub
subsub

Reputation: 1857

The reason is that both members and declarations only take into account object members. However, all functions declared in java.lang.System are static.

This makes sense because from the scala point of view there are no static members. The equivalent of a static member is a method/value defined in a module (using object instead of class). So scala-reflection will act as if static members of a Java-class are defined in a module --- more specifically in the companion object of the java-class. (Note that in contrast to scala defined companion objects these "java-companion-objects" do not exist on a VM level).

I'm no expert in scala reflection, so I can't tell you how you would find the static members :-(

Upvotes: 3

Related Questions