黒猿の家:Scalaの可視性パッケージ

Javaでは、それがこのクラスを含むパッケージに見える、官民または保護されたクラスのメンバとして宣言されていません。スカラ座では、修飾によって同じ効果を得ることができます。次のメソッドは、独自のパッケージに記載されています

package com.nick.impatient.people
class Person {
 private[people] def description="人的名字:" + name
}

尖叫提示:private 不写,默认是private[this],表示当前包或类中,private[people]指定到包范围的访问权限

もちろん、上位層パケットの視認性に拡張することが

private[impatient] def description="人的名字:" + name
package com.nick.impatient

class Cat{
 import com.nick.impatient.people.Person
 val person = new Person
 person.description
}

package people{
 class Person{
   private[impatient] def description = "人的名字:Nick"
 }

 class Dog{
   val person = new Person
   person.description
 }
}

ます。https://www.jianshu.com/p/5050aa5132f0で再現

おすすめ

転載: blog.csdn.net/weixin_34240657/article/details/91182487