logo
  • 教程列表
  • SO官方文档
  • 范围
    • 公共(默认)范围
    • 私人范围
    • 私有包特定范围
    • 对象私有范围
    • 受保护的范围
    • 包装保护范围
  1. StackOverflow 文档
  2. Scala Language 教程
  3. 范围
  4. 对象私有范围

对象私有范围

Created: November-22, 2018

限制最严格的范围是 “对象 - 私有” 范围,它只允许从对象的同一实例访问该值。

class FooClass {
  private[this] val x = "foo"
  def aFoo(otherFoo: FooClass) = {
    otherFoo.x // <- This will not compile, accessing x outside the object instance
  }
}
  • 受保护的范围
  • 私有包特定范围

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明