Skip to content

Commit 34d9241

Browse files
nateboschCommit Queue
authored andcommitted
Add a notice about HashMap keys changing hashCode
Closes #33384 Similar to a notice in the doc for `HashSet` where it is also unsafe to change `hashCode` while an object is in the collection. [email protected] Change-Id: I0e609656fccd563ecf71d4be5ecadafc1a6da891 CoreLibraryReviewExempt: Doc changes only. Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310774 Commit-Queue: Nate Bosch <[email protected]> Reviewed-by: Lasse Nielsen <[email protected]>
1 parent c50958a commit 34d9241

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

sdk/lib/collection/hash_map.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ typedef _Hasher<K> = int Function(K object);
3838
/// called during a [forEach] or [putIfAbsent] call,
3939
/// or while iterating the map ([keys], [values] or [entries]).
4040
///
41+
/// Do not modify keys in any way which changes their equality (and thus their
42+
/// hash code) while they are in the map. If a map key's [Object.hashCode]
43+
/// changes, it may cause future lookups for that key to fail.
44+
///
4145
/// Example:
4246
/// ```dart
4347
/// final Map<int, String> planets = HashMap(); // Is a HashMap

0 commit comments

Comments
 (0)