I was using someMap.get(someKey)
in my code, which gave me an error saying Please use !! or ?
. When I used someMap.getValue(someKey)
, that error disappeared.
Can someone explain why we have 2 seemingly similar looking (but weirdly different) get
function in Map
class?
UPDATE
I guess it has something to do with exception, that getValue
throws exception. But isnt it true that Kotlin doesnt have any exception throwing?
get
returns the value corresponding to the given key, or null if such a key is not present in the map, whilegetValue
returns the value for the given key or throws an exception if there is no such key in the map.