I’m currently learning Dart and have just written a class which extends a Base and uses the "super.* syntax" to initialize it. The member variable of the base which gets initialized is private and therefor prefixed with an underscore.
class X {
final int _i;
X(this._i);
}
class Y extends X {
Y(super.i);
}
For some reason though the compiler is happy with me omitting the underscore in the derived class. Why? Omitting it in the base generates a compiler error.
>Solution :
The Y(super.i) doesn’t use the name i for anything other than documentation.
The parameter is positional, and it’s forwarded to the same position in the superclass constructor without looking at the name at all. You could declare it Y(super.arglebargle) and it would work just the same.
Named parameters do use their names, so it’s only for positional super-parameters that you can write anything.