llsouder
02/06/2020, 3:49 AMSvyatoslav Kuzmich [JB]
02/06/2020, 10:18 AMunsafeCast does nothing but tricks type system into thinking that value is of different type without checking it at runtime. It should be used with great care.
We don't recommend casting 'bare' objects to Kotlin classes. While it might accidentally work in your case, class instances are more than just object, they include type metadata vital for type operators like as or is . data classes on top of that provide helper methods like copy, toString , hashCode, equals and these would be abcent from unsafeCast-ed bare object. Also, internal implementation of K/JS classes might change in the future releases and regular property access could break too.
In your case it would be more appropriate to either:
• Describe your objects using `external interface`s.
• Use library to parse JSON
There are, however, rare cases where unsafeCast could be useful. In performance-critical parts of the code, one might want to replace a regular as cast with unsafeCast if they know that it will always succed.llsouder
02/06/2020, 10:24 PMllsouder
02/06/2020, 10:25 PM