Comment #0 by verylonglogin.reg — 2014-07-18T10:50:12Z
This code should NOT compile:
---
final abstract class C { }
---
Such classes are almost useless and generally indicate an error. Note unless enhancement Issue 2946 is fixed the class may be derived as `abstract`:
---
final class C: B { }
---
`C` may or may no be `abstract` here depending on `B`. And one have to look through every ancestor of `C` to determine whether it contains an unimplemented `abstract` method.
Comment #1 by dfj1esp02 — 2014-07-18T13:06:53Z
In C# it's not an error, but a normal idiom when a class should not be inherited and instances should not be created.
Comment #2 by verylonglogin.reg — 2014-07-18T13:32:03Z
(In reply to Sobirari Muhomori from comment #1)
> In C# it's not an error, but a normal idiom when a class should not be
> inherited and instances should not be created.
1. In C# `class` can't be derived as `abstract`, it have to be explicitly marked so there is no `final class C` problem where reader may expect `C` to not be abstract.
2. In C# `class` can't be both `sealed` and `abstract` (error CS0418). Also there is `static` class syntax which ensures all class members are static and in D it's suggested to use modules with named imports for this purpose.
Note: `static` classes are implemented as `abstract sealed` on IL level, but it's not visible for the user and is just a workaround for languages without support for static classes.
Comment #3 by issues.dlang — 2014-07-19T01:33:01Z
I very much doubt that this will ever happen. It's used at least one place in Phobos (std.process.environment). Basically, it allows you to create a namespace within a module or to have a global singleton of sorts. You can do something similar by declaring a class whose default constructor is disabled, but regardless, some people are definitely using final abstract (or abstract final) on purpose, so I don't expect that it will ever become illegal.
Comment #4 by dfj1esp02 — 2014-07-19T13:36:37Z
Implementing final abstract as modules may be not an option, example: GCAllocator, which has only static members, but still has to be a single entity with a certain API - an allocator.
Comment #5 by robert.schadek — 2024-12-13T18:22:18Z