The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

audun (3) [Avatar] Offline
Quote from page 41: You state the reason for private members is to NOT create accessors, in the same example you show how accessors are created.

class MongoClient(private val _host:String, private val _port:Int) {
def host = _host
def port = _port
is equivalent to the class MongoClient(val host:String, val port:Int).
The reason we’re using private (you’ll learn about various access levels later in this chapter) is to
force Scala to not generate accessors for host and port values.
lutzhank (61) [Avatar] Offline
Re: self-conflicting??
Hello Audun,

I assume Nilanjan Raychaudhuri wants to show two things with one example:

What code Scala is generating when "val host" is used, like generating an accessor automatically and making the member private (which results in code like seen in the example) and

To express, that when we as developer use "private val host" explicitly, then Scala is not generating an accessor method automatically (which means the member, here "_host" is hidden within the class) and you have to add an accessor method manually if you want to access the value of the member from outside the class.

These two viewpoints though do not seem to contradict each other.

Hope this helps.

Best regards,