1
.toList(), , , , .
:
data class Notebook(private val _notes: List<String>) {
val notes: List<String> = _notes.toList()
}
, .equals() .hashCode() .
, :
class Notebook(notes: List<String>) {
val notes: List<String> = notes.toList()
}
2
Kotlin , , : https://github.com/Kotlin/kotlinx.collections.immutable
3
- , MutableList. , Klutter, , , . , . , . , . . Clutter ReadOnly Collection Wrappers .
Klutter :
data class Notebook(val notes: ReadOnlyList<String>) {
, , :
val myList = mutableListOf("day", "night")
Notebook(myList.toImmutable()) // copy and protect
, , ( asReadOnly()) , - , .
Klutter , ReadOnly vs. Immutable, , asReadOnly(), - . ( Klutter) , factory - (.. internal). , , . - , asReadOnly(), toImmutable() internal.
</" >
. : ?