How to expose a constructor variable(sic!) as read-only?
Posted
by Malax
on Stack Overflow
See other posts from Stack Overflow
or by Malax
Published on 2010-01-07T19:34:42Z
Indexed on
2010/05/03
16:58 UTC
Read the original article
Hit count: 222
scala
|best-practices
Hi StackOverflow!
I have this rather simple question about Scala. Given that i have to following class definition:
class Foo(var bar: Int)
The code which is able to construct an instance of Foo
must be able to pass the initial value for bar
. But if I define bar
as var
the User is also able to change its value at runtime which is not what I want. The User should only be able to read bar
. bar
itself is modified internally so a val
is not an option.
I think I might be getting an answer very soon as this question is so simple. :-)
Cheers, Malax
© Stack Overflow or respective owner