@@ -478,21 +478,15 @@ abstract interface class Map<K, V> {
478
478
/// ]);
479
479
/// print(map); // {1: A, 2: B, 3: C, 4: D}
480
480
/// ```
481
- ///
482
- /// Do not extend or implement the `MapEntry` class.
483
- /// If the Dart language introduces value types,
484
- /// the `MapEntry` class will be changed to such a type,
485
- /// and will likely no longer be able to be implemented or extended
486
- /// by classes.
487
- final class MapEntry <K , V > {
481
+ extension type const MapEntry <K , V >._((K , V ) asPair) implements Object {
488
482
/// The key of the entry.
489
483
///
490
484
/// ```dart
491
485
/// final map = {'theKey': 'theValue'}; // Map<String, String>
492
486
/// var entry = map.entries.first; // MapEntry<String, String>
493
487
/// print(entry.key); // 'theKey'
494
488
/// ```
495
- final K key;
489
+ K get key => asPair.$1 ;
496
490
497
491
/// The value associated to [key] in a map.
498
492
///
@@ -501,15 +495,8 @@ final class MapEntry<K, V> {
501
495
/// var entry = map.entries.first; // MapEntry<String, String>
502
496
/// print(entry.value); // 'theValue'
503
497
/// ```
504
- final V value;
498
+ V get value => asPair.$2 ;
505
499
506
500
/// Creates an entry with [key] and [value] .
507
- const factory MapEntry (K key, V value) = MapEntry <K , V >._;
508
-
509
- const MapEntry ._(this .key, this .value);
510
-
511
- /// String representation intended for debugging only.
512
- ///
513
- /// Not guaranteed to be stable over time.
514
- String toString () => "MapEntry($key : $value )" ;
501
+ const MapEntry (K key, V value): this ._((key, value));
515
502
}
0 commit comments