阅读Value Classes and Universal Traits后,我看了RichInt
的例子。Value Class w /`val`字段
但是,我更改了self
字段以取消val
。
scala> class RichInt(self: Int) extends AnyVal {
| def toHexString: String = java.lang.Integer.toHexString(self)
| }
<console>:7: error: value class parameter must be a val and not be private[this]
class RichInt(self: Int) extends AnyVal {
^
我得到了编译时错误。看来,在该字段中省略val
结果的可访问性为private[this]
。
保持与排除val
有什么意义?我不确定must be a val
究竟意味着什么。
这个话题似乎是相似的http://stackoverflow.com/questions/17944356/value-classes-introduce-unwanted-public-methods –