dave08
08/01/2023, 8:35 AMinterface FooBase<S> {
val state: Flow<S>
}
public abstract class Foo<S>(): FooBase<S> {
override val state: Flow<S> get() { ... }
}
// I'd like to have this as a state flow (I need to pass this to users of MyFoo, because there could be other implementations... but they need StateFlow, so I can't use Foo):
abstract class MyFooBase : Foo<Bar> {
override abstract val state: StateFlow<Bar>
}
class MyFoo : MyFooBase<Bar> {
override val state: StateFlow<Bar> by lazy {
super.state...stateIn(...)
}
}
But I get an error abstract-member-cannot-be-access-directly-kotlin
... is there any way to do this?Sam
08/01/2023, 9:11 AMFoo
, can you just make a new class that implements FooBase
and delegates to a private instance of Foo
?dave08
08/01/2023, 9:15 AMdave08
08/01/2023, 9:15 AMSam
08/01/2023, 9:19 AMclass MyFoo<S>(delegate: FooBase<S>, scope: CoroutineScope): FooBase<S> by delegate {
override val state: StateFlow<Bar> by lazy {
delegate.state.stateIn(scope)
}
}
dave08
08/01/2023, 9:20 AMSam
08/01/2023, 9:21 AMSam
08/01/2023, 9:21 AMdave08
08/01/2023, 9:21 AMdave08
08/01/2023, 9:24 AM