0
爲什麼不能複製具有var值更改的數據類對象?更改var值的Kotlin數據類複製
data class AppState(var list: List<Image> = ArrayList<Image>(),
val uiState: UIState = UIState.LIST,
val isFetching: Boolean = false)
...
val list = state!!.list.sublist(0,1);
state.copy(list = list) // No change
state.copy(isFetching = true) // Works like a charm
你知道'copy'返回一個新的實例,並且不修改接收者? – nhaarman