Created
February 24, 2014 13:13
-
-
Save goldeneggg/9188185 to your computer and use it in GitHub Desktop.
private var と private[this] var の違い
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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