<div dir="ltr">Filling up the rest of the details for the proposal:<div><br></div><div><div><b>Motivation</b></div><div><span style="white-space:pre-wrap">&quot;It is not uncommon to have a need for a reference type without a need for inheritance.  Superclasses should be intentionally designed to be subclasses and the author required to opt-in to subclassing and member overrides where that is required by the design.&quot;</span><br></div><div><span style="white-space:pre-wrap"><br></span></div><div><span style="line-height:1.5"><b>Proposed solution</b></span><br></div><div><span style="line-height:1.5">A keyword would be needed for both methods and classes. There are 2 options (this is not a final proposal since I don&#39;t have great answers for all the questions. Hoping other folks will chip-in :) )</span></div><div><span style="line-height:1.5">- The keyword to specify that a class is &quot;inheritable&quot; is the same as the keyword to specify that a method is &quot;overridable&quot;: this has the benefit of adding fewer keywords to the language, but it conflates 2 ideas that are not exactly the same.</span></div><div><span style="line-height:1.5">- Different keywords</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">As for what those keywords could be: Is there precedent in other languages for final-by-default? The only example I know of kind-of this is C++, where methods have to be specified &quot;virtual&quot; (even though that doesn&#39;t have quite the same semantics).</span></div><div><span style="line-height:1.5">I dislike the term &quot;virtual&quot; because it conveys implementation details, rather than developer intention. Ideally the keywords would communicate &quot;I meant for this class to be subclassable, and these are the methods that you can / must override &quot;, and users of Swift shouldn&#39;t have to know what a v-table is.</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">I don&#39;t have great ideas for keywords. All the ones I can think of are: &quot;nonfinal&quot; &quot;inheritable&quot; &quot;overridable&quot;, which are not great to say the least.</span></div><div><span style="line-height:1.5"><br></span></div><div><b>Other aspects</b></div><div>When methods are overriden, design often requires that the super implementation be called, sometimes even at a specific time (before / after the new implementation). Should this change also provide support for this sort of pattern, or would that be beyond the scope? (Note that this was possible in Obj-C with <i>NS_REQUIRES_SUPER</i>)</div><div><br></div><div><b>Impact on existing code</b></div></div><div>This change would break any classes that subclass a class that hasn&#39;t been marked as &quot;non-final&quot;, and all methods that override the implementation of a method also not marked as &quot;non-final&quot;.</div><div>The compiler could warn about this in the error however, with a message along the lines of &quot;<i>this class/method inherits/overrides a class/method that&#39;s not marked with the &quot;nonfinal&quot; keyword</i>&quot;.</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 7, 2015 at 11:12 AM Javier Soto &lt;<a href="mailto:javier.api@gmail.com">javier.api@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="white-space:pre-wrap">This was brought up in a different thread about private by default. Creating a new thread for this. Quoting Mathew from the other thread with a short summary about the motivation behind this:<br><br>&quot;It is not uncommon to have a need for a reference type without a need for inheritance.  Superclasses should be intentionally designed to be subclasses and the author required to opt-in to subclassing and member overrides where that is required by the design.&quot;</div><div dir="ltr">-- <br></div>Javier Soto</blockquote></div><div dir="ltr">-- <br></div>Javier Soto