Avatar ·

How to safely cast List<Any?> to List<Waypoint> in Kotlin? Unchecked Cast

Hi everyone! I just started learning Kotlin and encountered a problem with type casting of lists. I have a function that returns `List`. Inside this function, I know for sure that all elements are objects of my `Waypoint` class. But when I try to assign the result to a variable of type `List`, the compiler gives a warning: "Unchecked Cast: kotlin.collections.List to kotlin.collections.List". Here is an example code: ```kotlin data class Waypoint(val latitude: Double, val longitude: Double, val name: String) fun getData(): List { // Suppose this comes from an external source (JSON, database) return listOf( mapOf("lat" to 55.75, "lon" to 37.62, "name" to "Moscow"), mapOf("lat" to 59.93, "lon" to 30.