|
Re: Scala: The Static Language that Feels Dynamic
|
Posted: Oct 1, 2011 8:59 PM
|
|
Bruce Eckel seems being confused by val variables and immutable objects. In this article, Bruce wrote "A val is immutable, which is preferred in Scala because it makes concurrent code easier to write". Immutable objects make concurrent code easier to write. val variables do not help so much to easy concurrent code. Bruce also wrote "And class fields default to public -- which is not a big deal if you can stick to val, since that makes it read-only." A val variable won't make a public field of the object referenced by it read-only. If the object is mutable, its public fields won't be read-only. Referencing an object with a val variable won't make that object immutable. If an object with a public field is mutable, referencing it with a val variable won't stop a client programmer to directly manipulate the public field. For more details, see my article (http://ted-gao.blogspot.com/2011/10/immutable-objects-and-val-variables-are.html)
|
|