You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Methods in an anonymous class don't have consistent scope. In the following example, bar in foo is private, but in foo2, adding a temp variable will make it public.
Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions for evaluation. Or try :help.
scala> :paste
// Entering paste mode (ctrl-D to finish)
class A {}
def foo: A = new A { def bar(): Unit = {} }
def foo2: A = {
val temp = new A { def bar(): Unit = {} }
temp
}
// Exiting paste mode, now interpreting.
defined class A
foo: A
foo2: A
scala> foo.getClass.getDeclaredMethods().filter(_.getName == "bar").toList
res0: List[java.lang.reflect.Method] = List(private void $anon$1.bar())
scala> foo2.getClass.getDeclaredMethods().filter(_.getName == "bar").toList
res1: List[java.lang.reflect.Method] = List(public void $anon$2.bar())
This is pretty annoying when trying to call bar using reflection. I expect in this example, bar should be public.
Scala version: 2.12.1
Java version: 1.8.0_45
The text was updated successfully, but these errors were encountered:
Methods in an anonymous class don't have consistent scope. In the following example,
bar
infoo
is private, but infoo2
, adding a temp variable will make it public.This is pretty annoying when trying to call
bar
using reflection. I expect in this example,bar
should be public.Scala version: 2.12.1
Java version: 1.8.0_45
The text was updated successfully, but these errors were encountered: