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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.