June 2018
Intermediate to advanced
316 pages
6h 34m
English
Kotlin has both mutable and immutable collections. Having implicit control over whether collections can be edited is useful for writing clear and reliable code. It's important to understand that immutable collections in Kotlin are simply read-only, as the JVM doesn't see a difference between an immutable and mutable collection.
Let's look at the simplified version of the Collections.kt file:
public fun <T> emptyList(): List<T> = EmptyListpublic fun <T> listOf(vararg elements: T): List<T> = if (elements.size > 0) elements.asList() else emptyList()public inline fun <T> listOf(): List<T> = emptyList()public fun <T> listOf(element: T): List<T> = java.util.Collections.singletonList(element)public inline fun <T> mutableListOf(): ...
Read now
Unlock full access