Skip to content

Instantly share code, notes, and snippets.

@goldeneggg
Created February 24, 2014 13:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldeneggg/9188185 to your computer and use it in GitHub Desktop.
Save goldeneggg/9188185 to your computer and use it in GitHub Desktop.
private var と private[this] var の違い
// private なら、同一クラスの他オブジェクトからアクセス可能
scala> class Hoge (private var aho: Int) { def debug(hoge: Hoge) { println(hoge.aho) } }
defined class Hoge
// private[this] なら、同一クラスの他オブジェクトからアクセス不可
scala> class Huga (private[this] var aho: Int) { def debug(huga: Huga) { println(huga.aho) } }
<console>:7: error: value aho is not a member of Huga
class Huga (private[this] var aho: Int) { def debug(huga: Huga) { println(huga.aho) } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment