Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why mutableMapOf returns nullable?

I wrote a simple code block to store fragments with ids in Map. The value and key of map is initialized as non-nullable but when I want to get them as key and value, it gives nullable type data. So, I don't understand why? Is there any other type of map that returns non-nullable data in Kotlin?

enter image description here

like image 776
Amiraslan Avatar asked Dec 14 '22 21:12

Amiraslan


1 Answers

It is possible that there is no value for key [position], which will make it return null:

abstract operator fun get(key: K): V?

Returns the value corresponding to the given key, or null if such a key is not present in the map.

like image 146
nhaarman Avatar answered Dec 30 '22 00:12

nhaarman