Map does not have a null-aware-chainable "get" method #36541
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
library-collection
Take the following example:
I am accessing the first element of
listOfMaps
, guarding against null, withlistOfMaps?.elementAt
. However, iflistOfMaps
is null, then so islistOfMaps?.anything
, so an exception will be raised when ultimately[]
is called on null.The solution to this for property access is to chain null-aware all the way down, i.e.
foo?.bar.baz.quux
should befoo?.bar?.baz?.quux
to be safe. But this cannot be done for operators like[]
.In the case of a List, you can replace
list[i]
withlist?.elementAt(i)
, but there is no equivalent method for Map. I proposeV get(K key)
orV get(Object key)
.The text was updated successfully, but these errors were encountered: