Skip to content

Instantly share code, notes, and snippets.

@manjuraj
Last active August 29, 2015 14:20
Show Gist options
  • Save manjuraj/4eacc2cff6963733b28c to your computer and use it in GitHub Desktop.
Save manjuraj/4eacc2cff6963733b28c to your computer and use it in GitHub Desktop.
private[this]
//
// 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