dave08
12/22/2021, 12:15 PMsealed interface Foo<R>
object NoFoo : Foo<Nothing>
data class SomeFoo<R> : Foo<R>
// Is there any way this could work? (It doesn't... even though I don't use the R in NoFoo)
val baz: Foo<Baz> = NoFoo
Rob Elliot
12/22/2021, 12:56 PM<out R>
Rob Elliot
12/22/2021, 12:56 PMsealed interface Foo<out R>
object NoFoo : Foo<Nothing>
data class SomeFoo<out R>(val r: R) : Foo<R>
interface Baz
val baz: Foo<Baz> = NoFoo
dave08
12/22/2021, 1:09 PMin
with Any
instead of Nothing
...Rob Elliot
12/22/2021, 1:40 PMin Any
sounds like a pretty useless type.dave08
12/22/2021, 1:43 PM() -> Foo<SomeType>
then, if I have a SomeFoo
as a result of that callback, then I need it in something like setResult(someFoo.value)
Rob Elliot
12/22/2021, 1:56 PMsealed interface Foo<out R> {
val value: R
}
object NoFoo : Foo<Nothing> {
override val value: Nothing
get() = error("unsupported")
}
data class SomeFoo<out R>(override val value: R) : Foo<R>
Rob Elliot
12/22/2021, 1:58 PMval foo: Foo<String> = TODO()
if (foo is SomeFoo) {
setResult(foo.value)
}
Rob Elliot
12/22/2021, 1:59 PMkotlin.Result
?dave08
12/22/2021, 5:01 PMkotlin.Result
only has the last two...dave08
12/22/2021, 5:02 PM<Any>
there is so bad... compared to the alternatives that are much more verbose...?dave08
12/22/2021, 5:03 PMdave08
12/22/2021, 5:04 PM