Last active
August 29, 2015 14:20
-
-
Save manjuraj/4eacc2cff6963733b28c to your computer and use it in GitHub Desktop.
private[this]
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 members are visible to the companion class/trait | |
// and other instances of the class, but private[this] | |
// members are not | |
// | |
// A class member marked private: `private val x: Int = ...` | |
// is visible to all instances of that class (but not their | |
// subclasses). In most cases, you want private[this]. | |
// | |
// `private[this] val x: Int = ...` limits visibility to the | |
// particular instance. The Scala compiler is also able to | |
// translate private[this] into a simple field access (since | |
// access is limited to the statically defined class) which | |
// can sometimes aid performance optimizations. | |
// | |
// So, use private[this] where performance really matters | |
// because with private[this] you access a field directly | |
// instead through accessor methods | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment