operator [] method

V operator [] (Object key)
override

Returns the value for the given key or null if key is not in the map.

Some maps allow keys to have null as a value. For those maps, a lookup using this operator cannot distinguish between a key not being in the map and the key having a null value. Methods like containsKey or putIfAbsent can be used if the distinction is important.

Implementation

V operator [](Object key) {
  for (var map in _maps) {
    // Avoid two hash lookups on a positive hit.
    var value = map[key];
    if (value != null || map.containsKey(value)) {
      return value;
    }
  }
  return null;
}