[swift-evolution] Unify `static` and `class` keywords
John McCall
rjmccall at apple.com
Mon Dec 7 13:40:59 CST 2015
> On Dec 7, 2015, at 11:34 AM, Matthew Johnson <matthew at anandabits.com> wrote:
>
>
>> One important difference between “static” and “class” on a class is the behavior of storage. In principle, a static variable in a class is just a rescoped global (although it is unclear how this is affected by generics). A class variable in a class is conceptually a member of the class, and subclasses should get a separate copy.
>
> I understand that this is the case in general, but is it still the case when a class variable is marked as final in its initial declaration?
Yes. “final” means that it can’t be given different semantics in a subclass, not that it’s no longer a separate variable.
John.
> If class variables do behave differently even when declared final I wonder whether the use cases for this behavior are compelling enough to justify the conceptual complexity of two different keywords. I would be very interested in seeing examples of using a final class variable where separate storage for each subclass is desirable and useful.
More information about the swift-evolution
mailing list