Kotlin checked cast from Any? to Map<String,Any>

Viewed 4365

I have Any? coming from java and I would like to make a checked cast in order not to generate following warning:

Unchecked cast Any? to Map<String,Any>

Is it possible?

1 Answers

You can cast to Map<*, *>, but there's no way to check the type parameters. If you are sure that if it's a Map, then it's a Map<String, Any> (that is, all keys are Strings and values are never null) then just cast and suppress the warning with @Suppress("UNCHECKED_CAST").

Related