Unsafe cast operator (as) fails due to incompatible runtime object type.
Kotlin's unsafe cast operator `as` throws a `ClassCastException` if the target object cannot be cast to the specified type.
Casting `anyValue as String` when `anyValue` is an `Int` or a non-matching type.
1fun main() {2 val data: Any = 1003 val text: String = data as String // Throws ClassCastException!4 println(text)5}1fun main() {2 val data: Any = 1003 4 // Fix 1: Safe cast operator (as?) returns null on failure5 val text: String? = data as? String6 println("Text: $text") // Outputs: Text: null7 8 // Fix 2: Smart casting with 'is' check9 if (data is String) {10 println("Length: ${data.length}") // Kotlin smart-casts data to String11 } else {12 println("Data is not a String.")13 }14}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
`data` holds an integer (`100`). Unsafely forcing `data as String` fails at runtime.