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

  • 關於本站
  • 免責聲明