Allow sub-class methods to make superclass method parameters optional. #2824
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-duplicate
Closed in favor of an existing report
type-enhancement
A request for a change that isn't a bug
If you have a class A:
class A{
foo(int a, int b) {}
}
please make it possible to specialize this by making some parameters optional, e.g.:
class B extends A {
foo(int a, [int bar]) {}
}
(ditto for interfaces).
This is a safe generalization of the superclass interface, since all calls to the superclass method are still valid for the subclass.
It also allows a unified implementation of different interfaces, e.g.,
interface I {
foo(int a, int b);
}
interface J {
foo(String v);
}
class Unifier implements I,J {
foo(Object x, [int bar]) {]
}
This is currently not possible, because for one function type to be a subtype of another, they need to have the same number of non-optional arguments.
The text was updated successfully, but these errors were encountered: