-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Growable list constructor #21406
Comments
The current List constructor is designed the way it is in order to allow compilers to statically detect whether the resulting list is growable or not. That is why That said, I'm not unsympathetic to the suggestion, even if it will add overhead to the simple case. The growable parameter has to default to Added Library-Core, Triaged labels. |
One complication, which is probably fatal for this idea, is that we can't add growable as a named parameter, because the function already has an optional positional parameter, and Dart doesn't allow both optional positional and optional named parameters on the same function. |
This comment was originally written by sugashi.swi...@gmail.com Thanks.I understand why cannot add growable as a named parameter. But I want to know a possibility if growable are the second positional paramerter. that means, new List(); //growable and empty |
It's possible, but I think it would not be desirable. Since an easy workaround is to create a factory method: List makeList(int length, {bool growable: true}) => and use that instead of (It's slightly harder if you want type parameters: I'd rather wait until Dart allows both optional named and positional arguments on the same function (if that ever happens, but I'll keep crossing my fingers, and starring http://dartbug.com/7056). |
Added Triaged label. |
Fwiw it should be easy to just write: []..length=XY; |
This issue was originally filed by sugashi.s...@gmail.com
What steps will clearly show the issue / need for enhancement?
2.
3.
What is the current output?
var list = new List()..length = 10;
What would you like to see instead?
var list = new List(10, growable:true);
Please provide any additional information below.
growable should be true in default.
The text was updated successfully, but these errors were encountered: