Scala 访问权限控制——Scala Access Modifiers
来源:互联网 发布:js观察者模式 阮一峰 编辑:程序博客网 时间:2024/06/05 17:24
其他的都和Java的差不多,唯一的区别是多了Scope protect
Scope of protection
Access modifiers in Scala can be augmented with qualifiers. A modifier of the form private[X] or protected[X] means that access is private or protected "up to" X, where X designates some enclosing package, class or singleton object. Consider the following example:
package society { package professional { class Executive { private[professional] var workDetails = null private[society] var friends = null private[this] var secrets = null def help(another : Executive) { println(another.workDetails) println(another.secrets) //ERROR } } }}
Note the following points from the above example:
Variable workDetails will be accessible to any class within the enclosing packageprofessional.
Variable friends will be accessible to any class within the enclosing packagesociety.
Variable secrets will be accessible only on the implicit object within instance methods (this).
Spark中到处都可以看到 Scope of protection, 例如以下代码段
// Create the Spark execution environment (cache, map output tracker, etc) private[spark] val env = SparkEnv.create( conf, "<driver>", conf.get("spark.driver.host"), conf.get("spark.driver.port").toInt, isDriver = true, isLocal = isLocal) SparkEnv.set(env) // Used to store a URL for each static file/jar together with the file's local timestamp private[spark] val addedFiles = HashMap[String, Long]() private[spark] val addedJars = HashMap[String, Long]() // Keeps track of all persisted RDDs private[spark] val persistentRdds = new TimeStampedHashMap[Int, RDD[_]] private[spark] val metadataCleaner = new MetadataCleaner(MetadataCleanerType.SPARK_CONTEXT, this.cleanup, conf) // Initialize the Spark UI private[spark] val ui = new SparkUI(this)
0 0
- Scala 访问权限控制——Scala Access Modifiers
- Scala 访问权限控制——Scala Access Modifiers
- 访问控制修饰符(access modifiers)
- Scala访问控制修饰符
- Scala基础—再谈控制语句
- 【云星数据---Scala实战系列(精品版)】:Scala入门教程062-Scala实战源码-访问权限
- OCJP(310-065)精选笔记之-访问控制修饰符 (Access Modifiers)
- scala —— maven scala项目开发
- scala-school_concurrency in scala—Thread based
- scala-school_concurrency in scala—Actors based
- Scala访问权限修饰符:private和private[this]
- Scala学习笔记(四)----private的访问权限
- scala基础3 —— 表达式和控制结构
- scala基础——控制结构和函数
- 《快学Scala》——控制结构和函数
- Scala语法(二)——控制结构
- scala——trait
- Scala——函数
- LeetCode OJ:Flatten Binary Tree to Linked List
- 浅谈android的跑马灯效果(文字滚动)
- 大学三年积累的教学资源分享和推荐!
- VS2010中仅一次配置opencv的方法
- 机器学习的最佳入门学习资源
- Scala 访问权限控制——Scala Access Modifiers
- Android中内置的图片资源
- regexbuddy 教程
- sqlldr使用
- 阿里巴巴未来图
- rsync使用说明
- jquery css 操作
- 1623. Sixth Grade Math 求最大公约数和最小公倍数的
- 基于xmpp openfire smack开发之Android客户端开发[3]