A Modest Proposal: Final class instances

Walter Bright newshound1 at digitalmars.com
Tue May 5 10:30:42 PDT 2009


dsimcha wrote:
> == Quote from Walter Bright (newshound1 at digitalmars.com)'s article
>> dsimcha wrote:
>>> A possible
>>> solution is, given a class:
>>>
>>> class Foo {
>>>     // Actual implementation.
>>> }
>>>
>>> final class FooFinal : Foo{
>>>     // Dummy that just makes Foo final.
>>> }
>> With dmd:
>>    final class A { }
>>    class B : A { }
>> Compiling:
>>    test.d(2): Error: class test.B cannot inherit from final class A
> 
> Uh...I think you misread this.  I was inheriting from a non-final class to make it
> final, not the other way around.


Since all classes inherit from Object, this does indeed do what you 
asked for.

Try it. You'll find it "finalizes" the class. I'd also suggest trying 
out some calls to virtual functions in a final class, and running the 
result through obj2asm to see what happens.



More information about the Digitalmars-d mailing list