If you take a look at the List interface you can see that the generic type is marked as out, this means that E (the generic type) is only ever returned. The Kotlin compiler figures out that if List<Boolean> only produces Boolean it also only produces Any (since Boolean extends Any).
The Map interface has its V (value) type marked as out as well. But not its K (key) type, since it’s both accepted Map.get(key) and returned Map.keys. If a type is not marked with in or out, it’s considered invariant. The compiler won’t allow you to upcast or downcast generic invariant types. Thus, Map<String,String> -> Map<Any,Any> isn’t allowed.
val mapString: Map<String, String> = mapOf()
val mapAnyAny: Map<Any, Any> = mapString // assume this is possible
val item = mapAnyAny[2]
Map.get() function of mapString was supposed to receive keys of type String. But we just provided Int to it. As a result, this cast is not really type-safe.
Note it is possible to cast mapString to Map<String, Any> - this is save, because when we acquire String values from the map, each String is at the same Any.