Not as such. If you write a constructor, you can’t get the superclass constructor’s default value automatically in any way, and you have to either pass the parameter to the superconstructor or not in the initializer list. It can’t depend on the value of the subclass constructor’s parameter. So, you have to write the superclass constructor parameter default value again.
The one hack you can do (and I don’t recommend doing it just for this) is that if the parameters to the subclass constructor is exactly the same as the superclass constructor, you can declare the members of your subclass in a mixin
and make the subclass be a mixin application.
So instead of:
class SuperClass {
SuperClass(...args) : ...
...
}
class SubClass extends SuperClass {
SubClass(...args) : super(...args);
members() ...
}
you do:
class SuperClass {
SuperClass(...args) : ...
...
}
mixin _SubClass on SuperClass {
members() ...
}
class SubClass = SuperClass with _SubClass;
That will give SubClass
a constructor for each superclass constructor, with the same parameters (including default values), which forwards directly to the superclass constructor.
Don’t do this just to avoid writing the default value again!
CLICK HERE to find out more related problems solutions.