Reputation: 26513
I have Any?
coming from java and I would like to make a checked cast in order not to generate following warning:
Is it possible?
Upvotes: 6
Views: 9620
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 String
s and values are never null
) then just cast and suppress the warning with @Suppress("UNCHECKED_CAST")
.
Upvotes: 7