BuiltMap<K, V> constructor

BuiltMap<K, V>(
  1. [dynamic map = const {}]
)

Instantiates with elements from a Map or BuiltMap.

Must be called with a generic type parameter.

Wrong: new BuiltMap({1: '1', 2: '2', 3: '3'}).

Right: new BuiltMap<int, String>({1: '1', 2: '2', 3: '3'}).

Rejects nulls. Rejects keys and values of the wrong type.

Implementation

factory BuiltMap([map = const {}]) {
  if (map is _BuiltMap && map.hasExactKeyAndValueTypes(K, V)) {
    return map as BuiltMap<K, V>;
  } else if (map is Map || map is BuiltMap) {
    return _BuiltMap<K, V>.copyAndCheckTypes(map.keys, (k) => map[k]);
  } else {
    throw ArgumentError('expected Map or BuiltMap, got ${map.runtimeType}');
  }
}