Seri
08/14/2019, 6:39 PMabstract class State
with some helper functions, can I have them return the child type, without it getting generalized to just “anything that inherits from `State`“?karelpeeters
08/14/2019, 6:42 PMAny
and you can still say you return a String
.Seri
08/14/2019, 6:44 PMSeri
08/14/2019, 6:46 PMabstract class State<S: State<S>>
and each child like so:
sealed class TestState: State<TestState>
Seri
08/14/2019, 6:46 PMShawn
08/14/2019, 6:55 PMShawn
08/14/2019, 6:55 PMShawn
08/14/2019, 6:55 PMShawn
08/14/2019, 6:55 PMShawn
08/14/2019, 6:55 PMShawn
08/14/2019, 6:58 PMabstract class State<S : State<S>> {
protected abstract fun self(): S
fun helperFunc(): S {
doHelperStuff()
return self()
}
}
Shawn
08/14/2019, 6:58 PMself()
method by just returning this
Shawn
08/14/2019, 6:59 PMS
and keeping things abstract works fineSeri
08/14/2019, 7:07 PMkarelpeeters
08/14/2019, 7:15 PMSeri
08/14/2019, 7:26 PM