pixel
pixel

Reputation: 26513

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

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?

Upvotes: 6

Views: 9620

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170899

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").

Upvotes: 7

Related Questions