0

It is weird to me that the class defined in scala shell is public static but not public, I don't know why, anyone knows ? Thanks

scala> class Split{}
defined class Split

scala> import java.lang.reflect.Modifier
import java.lang.reflect.Modifier

scala> val clazz = classOf[Split]
clazz: Class[Split] = class Split

scala> println(Modifier.toString(clazz.getModifiers))
public static
zjffdu
  • 25,496
  • 45
  • 109
  • 159

1 Answers1

0

All classes defined in shell are being enclosed by default. They are nested in other classes, which are defined by the shell.

scala> println(clazz.getName)
$line2.$read$$iw$$iw$Split

I guess, that they are static, because it was not the intention to give them any access to members of the enclosing class. Being static might come with advantages related to redefinition of the same class and with garbage collection. But I am fishing here, someone else can provide a more exact answer for sure.

ygor
  • 1,726
  • 1
  • 11
  • 23