febs
01/25/2019, 12:36 PMspand
01/25/2019, 12:39 PMgetValue()diesieben07
01/25/2019, 12:39 PMval s = listOfFeeds[key]
if (s == null) {
// code for null
} else {
// code for non-null
}
Alternatively you can use map.getOrDefault(key, defaultValue). Or, if you are really sure that it's not null you can use !! or checkNotNull(map[key])diesieben07
01/25/2019, 12:40 PMgetValueAlowaniak
01/25/2019, 1:39 PM?: is also possiblerook
01/25/2019, 4:12 PMval s: String
someMap["foo"]?.let { s = it } ?: throwNikky
01/26/2019, 1:32 AM[] indexing operator is just calling get which return a Nullable because the key might not exists
you can use a fallback values with ?: or throw in that case
i like to use ?.let { doSomethingWith(it)} personally
andyou could also just use !! to null assert