private[this] vs private

后端 未结 9 1067
悲哀的现实
悲哀的现实 2020-11-28 01:35

In Scala I see such feature as object-private variable. From my not very rich Java background I learnt to close everything (make it private) and open (provide accessors) if

9条回答
  •  清歌不尽
    2020-11-28 02:02

    private var name is accessible from any method of the class Dummy (and its companion object Dummy).

    private[this] var name is accessible from methods of this object only, not from other objects of class Dummy.

提交回复
热议问题