Arrays in Kotlin are invariant

Arrays in Kotlin are not built on native types, but are instead based on a Java array. Although these are similar, they do behave slightly differently. In Java, we can assign an array of a type to an array of its parent type. Arrays in Kotlin are invariant, which means that an array of a specific type cannot be assigned to an array of its parent type. It is not possible to assign Array<Integer> to Array<Any>. This provides implicit type safety and prevents possible runtime errors in the application. Kotlin also provides specialized classes to create arrays of primitive data types, including ByteArray, ShortArray, and IntArray.

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

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