Skip to content

Instantly share code, notes, and snippets.

@kevinmeredith
Last active December 27, 2016 18:24
Show Gist options
  • Select an option

  • Save kevinmeredith/6a7e272a5ed1b7f4bc25c1756a818919 to your computer and use it in GitHub Desktop.

Select an option

Save kevinmeredith/6a7e272a5ed1b7f4bc25c1756a818919 to your computer and use it in GitHub Desktop.
private versus private [this] in Scala 2.11
scala> :paste
// Entering paste mode (ctrl-D to finish)
class A(private [this] val x: Int)
object A {
def f(a: A) = a.x
}
// Exiting paste mode, now interpreting.
<console>:13: error: value x is not a member of A
def f(a: A) = a.x
^
scala> :paste
// Entering paste mode (ctrl-D to finish)
class B(private val x: Int)
object B {
def f(b: B) = b.x
}
// Exiting paste mode, now interpreting.
defined class B
defined object B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment