In Java, it is not declared as public, private or protected class members, visible in the package that contains this class. In Scala, you can achieve the same effect by modifier. The following methods can be found in its own package
package com.nick.impatient.people
class Person {
private[people] def description="人的名字:" + name
}
尖叫提示:private 不写,默认是private[this],表示当前包或类中,private[people]指定到包范围的访问权限
Of course, also be extended to the upper layer packet viewability
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
}
}
Reproduced in: https: //www.jianshu.com/p/5050aa5132f0