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

私人范围

Created: November-22, 2018

范围是私有的时,只能从当前类或当前类的其他实例访问它。

package com.example {
  class FooClass {
    private val x = "foo"
    def aFoo(otherFoo: FooClass) {
      otherFoo.x // <- Accessing from another instance of the same class
    }
  }
  class BarClass {
    val f = new FooClass
    f.x // <- This will not compile
  }
}
  • 私有包特定范围
  • 公共(默认)范围

Copyright © 2018. All right reserved

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

  • 关于我们
  • 免责声明