I’m wondering if the () must be required in the second line of this example:
open class Base
class Derived : Base()
I can declare the base class without brackets, it would be nice if the same were true for the inheritance relationship.
I’m wondering if the () must be required in the second line of this example:
open class Base
class Derived : Base()
I can declare the base class without brackets, it would be nice if the same were true for the inheritance relationship.
The parentheses indicate which of the base types of your class is a class (requiring parentheses) and which is an interface (where no parentheses are allowed).
Sorry, should have given more context.
I do know about this distinction. BUT:
Derived : Base
syntax was to do away with the distinction between extends
and implements
that you have in Java. I feel like requiring brackets sneaks this distinction back inI would find it more consistent if I could get rid of the brackets (or always require them class declarations). Just a thought
I’d like to see the () removed too, it’s just extra noise (make it optional so it doesn’t break anything).
The trade-off here is
Not so easy to tell which is better, really, so this cleasly goes under the “bikeshedding” category
If you think of a constructor call, this syntax makes sense. A constructor is more or less a function and you have to write parenthesis when calling parameterless functions, too.
For completeness, this variant should be included in the discussion:
open class Base
class Derived : Base {
constructor() : super()
}