`data` is a Request `sealed class` and inside that...
# android
i
data
is a Request
sealed class
and inside that class there 3 classes
Opened, Success, NotSigned
How I can cast
data
to have access to
data.openedFrom
value? I want to avoid invoking 3 times
navigate()
function
m
I have something very similar in my code and data should be cast as a Request.
Capture d’écran 2022-09-21 à 12.06.23 PM.png,Capture d’écran 2022-09-21 à 12.07.13 PM.png
where type in second screenshot is cast as AddEditCatDateEvent
Also if your Request class has no parameter, you should consider using a sealed interface instead.
j
Can you modify the definition of
Request
? Because it seems to me that well, if all the subtypes have a common
openedFrom
property, then that should also be reflected in their supertype. Something like
Copy code
sealed class Request {
  abstract val openedFrom: Instant

  data class Opened(override val openedFrom: Instant, foo: Int, bar: String) : Request()

  data class Success(override val openendFrom: Instant, baz: Long) : Request()
...
}
👍 2