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

  • 關於本站
  • 免責聲明