jeudi 26 octobre 2017

Scala reflection: Why does getMethods return private vals defined in superclass?

Code below defines a trait T with a private val someVal and an anonymous class extending T. If we call getMethods from the instance of the anonymous class, someVal is listed as a public method:

scala> trait T { private val someVal = 3 }
defined trait T

scala> new T {}.getClass.getMethods.apply(0)
res2: java.lang.reflect.Method = public int $anon$1.$line6$$read$T$$someVal()

Of course someVal isn't accessible in this subclass, but why is it even in the return of getMethods, as public?





Aucun commentaire:

Enregistrer un commentaire