# Type casts

**URL:** <https://discuss.kotlinlang.org/t/type-casts/727>\
**Category:** Uncategorized\
**Created:** [August 28, 2013, 4:36pm UTC](https://discuss.kotlinlang.org/t/type-casts/727 "2013-08-28T16:36:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![phifty](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phifty/32/1569_2.png) [@phifty](https://discuss.kotlinlang.org/u/phifty)\
**Post date:** [August 28, 2013, 4:36pm UTC](https://discuss.kotlinlang.org/t/type-casts/727/1 "2013-08-28T16:36:43Z")

</div>

Hello!

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\<\*, \*\>) {  
 &nbsp;&nbsp;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](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?

Best regards  
Philipp

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [August 29, 2013, 10:19am UTC](https://discuss.kotlinlang.org/t/type-casts/727/2 "2013-08-29T10:19:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![phifty](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phifty/32/1569_2.png) [@phifty](https://discuss.kotlinlang.org/u/phifty)\
**Post date:** [August 29, 2013, 11:08am UTC](https://discuss.kotlinlang.org/t/type-casts/727/3 "2013-08-29T11:08:22Z")

</div>

Thanks for the quick reply. Can you tell, if the smater compiler will be there in far or near future?

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [August 29, 2013, 12:12pm UTC](https://discuss.kotlinlang.org/t/type-casts/727/4 "2013-08-29T12:12:02Z")

</div>

I'm going to work on it in the next few days. The "suppress warnings" part will come a little later

---

<div class="post-metadata">

**Author:** ![phifty](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phifty/32/1569_2.png) [@phifty](https://discuss.kotlinlang.org/u/phifty)\
**Post date:** [August 30, 2013, 9:36am UTC](https://discuss.kotlinlang.org/t/type-casts/727/5 "2013-08-30T09:36:18Z")

</div>

Thanks! I'm going to watch out for new releases.

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

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [September 6, 2013, 8:18am UTC](https://discuss.kotlinlang.org/t/type-casts/727/6 "2013-09-06T08:18:35Z")

</div>

This functionality is now available in the fresh nightly builds.

---

<div class="post-metadata">

**Author:** ![phifty](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/phifty/32/1569_2.png) [@phifty](https://discuss.kotlinlang.org/u/phifty)\
**Post date:** [October 16, 2013, 3:02pm UTC](https://discuss.kotlinlang.org/t/type-casts/727/7 "2013-10-16T15:02:46Z")

</div>

Great! It seems to work now. Even the suppress warning seem to work. Thanks a lot.
