y
04/18/2023, 8:35 PMsealed class Foo {
class A(): Foo()
class B(): Foo()
class C(): Foo()
}
class Bar<F: Foo>(val f: F) { }
inline fun <F : Foo, reified RET : Bar<F>> doSomething(): List<RET> { //... }
now this is fine and I can call it with doSomething<F, Bar<F>>(), or I can make the function signature inline fun <reified RET : Bar<Foo>> doSomething(): List<RET>, and then call it with doSomething<Bar<F>>.
but what I'd really like to do is call it with doSomething<F>(). is this possible?Adam S
04/18/2023, 8:55 PMRET as a type parameter? It seems like since Bar is not open or abstract, you can just use Bar
inline fun <F : Foo> doSomething(): List<Bar<F>> { TODO() }y
04/18/2023, 8:58 PMdoSomething(), I have to do someVar is RET. which makes Kotlin complain that I'm checking for an instance of an erased type.Adam S
04/18/2023, 9:17 PMBar doesn’t need to be generic? Foo is always constrained to A, B, or C, so making Bar generic actually makes the typing less strict
class Bar(val f: Foo) { }
inline fun <F : Foo> doSomething(): List<Bar> { //... }y
04/18/2023, 9:26 PMdoSomething<Bar<F>>() is really not that bad.