Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Unified Diff: sdk/lib/core/list.dart

Issue 2100943003: Add documentation to List.filled to warn of common mistake. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/list.dart
diff --git a/sdk/lib/core/list.dart b/sdk/lib/core/list.dart
index 9d25927ef1e60372af1e5c5c1450968fa15347a7..d887e67600a65f636475b4d758f136eb93977ece 100644
--- a/sdk/lib/core/list.dart
+++ b/sdk/lib/core/list.dart
@@ -88,6 +88,24 @@ abstract class List<E> implements Iterable<E>, EfficientLength {
* entries with [fill]. After being created and filled, the list is
* no different from any other growable or fixed-length list
* created using [List].
+ *
+ * All entries in the returned list point to the same provided [fill] value.
+ * That all items in the list are the same object is
+ * observable when the given value is a mutable object.
+ *
+ * ```
+ * var shared = new List.filled(3, []);
+ * shared[0].add(499);
+ * print(shared); // => [[499], [499], [499]]
+ * ```
+ *
+ * You may use [List.generate] to create a new object for each position in
+ * in the list.
+ * ```
+ * var unique = new List.generate(3, (_) => []);
+ * unique[0].add(499);
+ * print(unique); // => [[499], [], []]
+ * ```
*/
external factory List.filled(int length, E fill, {bool growable: false});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698