operator [] method

  1. @override
BridgedClass? operator [](
  1. Object? key
)
override

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

Some maps allow 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 being there with a null value. Methods like containsKey or putIfAbsent can be used if the distinction is important.

Implementation

@override
BridgedClass? operator [](Object? key) {
  final cached = _memo[key];
  if (cached != null) return cached;
  final thunk = _thunks[key];
  if (thunk == null) return null;
  final built = thunk();
  _memo[key as K] = built;
  return built;
}