Daniel
10/13/2020, 7:30 PMprivate val _state = MutableStateFlow<Foo>(Foo())
val state = StateFlow<Foo> get() = _state
and
private val _state = MutableStateFlow<Foo>(Foo())
val state = StateFlow<Foo> = _state
?
Jetbrains and Google use the first form in their documentation, but isn't a val read-only regardless of whether it is specified as only having a getter or not?Zach Klippenstein (he/him) [MOD]
10/13/2020, 7:31 PMstreetsofboston
10/13/2020, 7:32 PMget() = was used and not plain `=`…Daniel
10/13/2020, 7:32 PMAlejandro Rios
10/13/2020, 7:32 PMDaniel
10/13/2020, 7:33 PMstatestreetsofboston
10/13/2020, 7:33 PMval state: StateFlow<Foo> = _state is a bit more performant… the get()= is not needed, in my opinionZach Klippenstein (he/him) [MOD]
10/13/2020, 7:33 PMstreetsofboston
10/13/2020, 7:34 PMget()= if = works as well? A plain field assignment seems simpler to meZach Klippenstein (he/him) [MOD]
10/13/2020, 7:34 PMstreetsofboston
10/13/2020, 7:35 PMprivate val _state = MutableStateFlow<Foo>(Foo())
val state: StateFlow<Foo> get() = _state
vs
private val _state = MutableStateFlow<Foo>(Foo())
val state: StateFlow<Foo> = _state
and the 2nd one seems sufficient… why the get()?Zach Klippenstein (he/him) [MOD]
10/13/2020, 7:35 PM// With get() =
private val _state: String
fun getState(): String = _state
vs
// Without get() =
private val _state: String
private val $_state: String = _state
fun getState(): String = $_stateZach Klippenstein (he/him) [MOD]
10/13/2020, 7:36 PMstreetsofboston
10/13/2020, 7:36 PMget()= won’t create yet another backing field.streetsofboston
10/13/2020, 7:37 PMAlejandro Rios
10/13/2020, 7:38 PMZach Klippenstein (he/him) [MOD]
10/13/2020, 7:38 PMstreetsofboston
10/13/2020, 7:38 PMZach Klippenstein (he/him) [MOD]
10/13/2020, 7:38 PMZach Klippenstein (he/him) [MOD]
10/13/2020, 7:39 PM