Adding syntacti sugar for simple "readonly" attribute ?
Jacob Carlborg
doob at me.com
Fri Oct 27 06:49:47 UTC 2017
On 2017-10-27 01:04, bauss wrote:
> The first example would not equal the second, because you could set bar
> from anywhere within the module.
>
> Immutable will already do your behavior.
>
> class Foo
> {
> immutable string bar;
>
> this(string baz)
> {
> bar = baz;
> }
> }
That only works for primitive types. For anything else (like a class or
struct) you won't be able to modify the internal state. While with the
with the initial example you can.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list