Safe type-casting 

Whenever we perform type-casting, we should keep in mind that it is a potential source of exceptions. That's the reason why we should always perform type-checking using the is modifier or do the casting inside the try…catch block. However, in Kotlin, we have also a safe casting option that will not throw ClassCastException but will return null instead. In this recipe, we are going to test the safe casting in action.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.152.123