ghedeon
12/25/2019, 11:19 AMinterface IFoo<A>
class Foo: IFoo<String>
class Bar<A>: IFoo<A>
inline fun <reified T: IFoo<*>> createBar(){
val type = T::class.supertypes[0].arguments[0].type // the type is not lost, String is here
Bar<type>() // ?? how to use it here
}
createBar<Foo>()
I know that I can declare something like fun <A, T:IFoo<A> createBar()
, but it's kind of repeating myself and the A
is already known...Animesh Sahu
12/25/2019, 11:31 AMBar<T>()
?Animesh Sahu
12/25/2019, 11:35 AMDico
12/25/2019, 11:35 AMDico
12/25/2019, 11:35 AMghedeon
12/25/2019, 11:39 AMBar<type>
? I mean, this line doesn't even compile 🙂Dico
12/26/2019, 12:22 AMghedeon
12/26/2019, 12:26 AMtype
variable holds the exact generic argument, which is String
here. So, it's more like a theorethical question, if it's possible to pass it to Bar<here>()
or not.Dico
12/26/2019, 12:58 AMDico
12/26/2019, 12:58 AMDico
12/26/2019, 12:58 AM