I’m searching for this topic for quite a while now. I’m trying to get rid of some warnings and would like to know how to do that.
val documentMap = parseJson(json) if (documentMap is MutableMap<*, *>) { return Document(documentMap as MutableMap<String, Any?>) } else throw Exception(“unknown structure”)
The third line produces an unchecked cast warning, which is right because documentMap is smart-casted to MutableMap<*, >. As described in http://confluence.jetbrains.com/display/Kotlin/Generics, the “is”-check can only be done with MutableMap<, *> and not directly against MutableMap<String, Any?>. How can I get rid of the warning that the unsafe “as”-cast produces?
We do not support "suppress warnings" yet, but we will.
Also, for the case when your documentMap is, say, Map<String, Any?>, we'll make the compiler smarter, so it'll figure out that your casts are OK.
I personally don’t care much about the feature to supress warnings. Always better to fix a warning than to supress it
From a developer point of view, it would be cool too if a smart-cast could cast directly to Map<String, Any?> instead of the generic variant Map<*, *>. But as I understand the documentation, that would have a bigger impact on kotlin internals and I guess it’s do-able in appropiate time.
Thanks for all the great work, that have be done so far.
Philipp