When declaring an interface, I’ve kinda automatica...
# getting-started
s
When declaring an interface, I’ve kinda automatically defaulted to not exposing fields, but exposing functions directly, but not quite sure why. I’ve now had this one case where I had an interface expose a
StateFlow<Foo>
and had it behind a function
stateFlow(): StateFlow<Foo>
but the implementation simply had the private declaration and the overridden function was simply doing
return this.stateFlow
. So I wonder, is it weird for the interface to simply expose
val stateFlow: StateFlow<Foo>
instead? Are there any reasons why I would want to avoid that?
s
your val is a getter and therefor also a function. I think it's fine in Kotlin, it's just something we're not used to in Java and that's why it feels weird.
s
Yes, that’s what I was thinking as well, I think that’s why it feels weird to me too, but I made the change and it’s just fine I think. Will keep it this way I think now 😄