0

What changes in a class when you declare a constructor value with val? I noticed that it behaves differently below:

scala> :paste
// Entering paste mode (ctrl-D to finish)

class Foo(value: String) extends Bar
class Bar { this: Foo =>
  def go = println(value)
}

// Exiting paste mode, now interpreting.

<console>:9: error: not found: value value
         def go = println(value)
                          ^

scala> :paste
// Entering paste mode (ctrl-D to finish)

class Foo(val value: String) extends Bar
class Bar { this: Foo =>
  def go = println(value)
}

// Exiting paste mode, now interpreting.

defined class Foo
defined class Bar
Daenyth
  • 35,856
  • 13
  • 85
  • 124
  • 1
    [This question](http://stackoverflow.com/questions/14694712/do-scala-constructor-parameters-default-to-private-val) could help you, basically having the `val` modifier creates a public getter. – Ende Neu May 08 '15 at 12:45
  • @EndeNeu you're right, I'm VTC as duplicate – Daenyth May 08 '15 at 12:46

0 Answers0