Effect of declaring a class immutable ?
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 26 07:52:08 PDT 2016
On Thursday, May 26, 2016 14:12:23 chmike via Digitalmars-d-learn wrote:
> I couldn't find any information about this on the dlang web site.
>
> What is the effect adding the immutable attribute to a class like
> this
>
> immutable class MyClass { ... }
>
> The compiler doesn't complain.
> Will it add the immutable attribute to all members ?
If you put any attribute on a class that's not specifically for a class
(like abstract or final), then it will mark all of its members with that
attribute, which is almost never what you want. It's equivalent to doing
something like
immutable
{
class MyClass
{
}
}
or
class MyClass
{
immutable:
}
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list