You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dart provides a default constructor for any class that does not explicitly define a constructor and those default constructors always have zero parameters. But if a class does not define an explicit constructor and it has uninitialized final members, wouldn't it be safe to assume that the programmer intends that the initializing values should be provided to the default constructor?
Example:
classPoint<Textendsnum> {
finalT x;
finalT y;
}
Because Point<T> does not define a constructor and it has unitialized final membersx and y, the default constructor provided by Dart would be:
constPoint(this.x, this.y)
In this example, the default constructor is const because all the members are final. In classes with non-final members, the default constructor would not be const.
The more uninitialized final members a class has, the more this proposal would help keep things succinct. An example from my current project:
Dart provides a default constructor for any class that does not explicitly define a constructor and those default constructors always have zero parameters. But if a class does not define an explicit constructor and it has uninitialized final members, wouldn't it be safe to assume that the programmer intends that the initializing values should be provided to the default constructor?
Example:
Because
Point<T>
does not define a constructor and it has unitialized final membersx
andy
, the default constructor provided by Dart would be:In this example, the default constructor is const because all the members are final. In classes with non-final members, the default constructor would not be const.
The more uninitialized final members a class has, the more this proposal would help keep things succinct. An example from my current project:
The text was updated successfully, but these errors were encountered: