static class

Ben Davis entheh at cantab.net
Wed Feb 20 15:39:29 PST 2013


On 18/02/2013 21:25, Michael wrote:
> Yes, it's comes from C#.
>
> So, there is no static for classes at module level. Good to have a msg
> for it at compile-time.
>
>> import std.stdio;
>>
>> public final abstract class Test
>> {
>>    static this() { writeln("in static ctor"); }
>>    static :
>>        void foo() { writeln("in static method"); }
>> }
>>
>> void main()
>> {
>>    Test.foo();
>> }
>
> public - adds a little bit of verbosity (ref
> http://wiki.dlang.org/Access_specifiers_and_visibility). For now is noop.
> final - adds a no inheritance.
> abstract - disables non-static ctors.
>
> right?

Technically 'abstract' doesn't disable the ctors; they would still be 
called by super() if you had a subclass (if you didn't use 'final'). 
What 'abstract' does is insist that all instances must be of some 
subtype, not of the class itself.

I'm sure you knew that and it's just a wording thing :)

Fun fact: in Java, it's an error to combine 'final' and 'abstract'.


More information about the Digitalmars-d-learn mailing list