private[this] vs private

后端 未结 9 1072
悲哀的现实
悲哀的现实 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:06

    I don't think it matters too much, since any changes will only touch one class either way. So the most important reason to prefer private over protected over public doesn't apply.

    Use private[this] where performance really matters (since you'll get direct field access instead of methods this way). Otherwise, just settle on one style so people don't need to figure out why this property is private and that one is private[this].

提交回复
热议问题