I'm confused by Kotlin's null safety features when it comes to maps. I have a Map<String, String>. Yet I can call map.get(null) and it returns null to indicate that the key is not present in the map. I expected a compiler error, because map is a Map<String, String> and not a Map<String?, String>. How come I can pass null for a String argument?
And a related question: is there any type of Map, be it a stdlib one or a third-party implementation, that may throw NullPointerException if I call get(null)? I'm wondering if it is safe to call map.get(s) instead of s?.let { map.get(it) }, for any valid implementation of Map.
Update
The compiler does indeed return an error with map.get(null). But that is not because of null safety, but because the literal null doesn't give the compiler an indication of the type of the parameter being passed. My actual code is more like this:
val map: Map<String, String> = ...
val s: String? = null
val t = map.get(s)
The above compiles fine, and returns null. How come, when the key is supposed to be a String which is non-nullable?