dart:core
庫中Map.unmodifiable
的用法介紹如下。
用法:
Map<K, V>.unmodifiable(
Map other
)
創建一個包含 other
條目的不可修改的基於哈希的映射。
鍵必須都是 K
的實例和 V
的值。 other
映射本身可以具有任何類型。
該Map需要鍵來實現兼容的 operator==
和 hashCode
。創建的映射以固定順序迭代鍵,保留 other
提供的順序。
結果映射的行為類似於 Map.from 的結果,除了此構造函數返回的映射不可修改。
final planets = <int, String>{1: 'Mercury', 2: 'Venus', 3: 'Earth'};
final unmodifiableMap = Map.unmodifiable(planets);
unmodifiableMap[4] = 'Mars'; // Throws
相關用法
- Dart Map.update用法及代碼示例
- Dart Map.updateAll用法及代碼示例
- Dart Map.addEntries用法及代碼示例
- Dart Map.removeWhere用法及代碼示例
- Dart Map.from用法及代碼示例
- Dart Map.remove用法及代碼示例
- Dart Map.fromIterable用法及代碼示例
- Dart Map.containsValue用法及代碼示例
- Dart Map.clear用法及代碼示例
- Dart Map.containsKey用法及代碼示例
- Dart Map.putIfAbsent用法及代碼示例
- Dart Map.of用法及代碼示例
- Dart Map.fromIterables用法及代碼示例
- Dart Map.forEach用法及代碼示例
- Dart Map.fromEntries用法及代碼示例
- Dart Map.addAll用法及代碼示例
- Dart MapMixin.containsKey用法及代碼示例
- Dart MapEntry.value用法及代碼示例
- Dart MapMixin.update用法及代碼示例
- Dart MapView.containsValue用法及代碼示例
- Dart MapMixin.putIfAbsent用法及代碼示例
- Dart MapMixin.addAll用法及代碼示例
- Dart MapMixin.clear用法及代碼示例
- Dart MapMixin.addEntries用法及代碼示例
- Dart MapView.clear用法及代碼示例
注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 Map<K, V>.unmodifiable constructor。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。