Just as stated in the title: Why is it possible to omit default values in overridden member functions of sub-types?
Is this normal or to be expected?
Yes, this is normal and to be expected.
Moreover, it is not allowed to override the default values. This does not compile:
interface Foo {
fun bar(parameter: Int = 1)
}
class Baz : Foo {
override fun bar(parameter: Int = 1) { // ERROR: An overriding function is not allowed to specify default values for its parameters
}
}
Technically the implementation with fixed default values is much simpler than any other implementation. For example Scala goes to a great extend to provide this capability, but the generated byte code is not a simple one.
Is this normal or to be expected?
Yes.
I suspect this was primarily a language design / usability decision. From this perspective, there were four options available:
The Kotlin designers chose option #1. This makes sense because:
Option #2 and #4 all imply that callers would not know what the default value is unless they were aware of which implementation they were using, which is of course highly undesirable. The caller would require extra logic to determine if a value is needed to override a default, which means the default would be useless.
Option #3 violates the DRY principle. Why force the declaration to be in two places?
That leaves Option #1 as the only sane choice.