https://kotlinlang.org logo
e

ephemient

11/07/2021, 12:09 PM
Given a
Copy code
annotation class Foo<T>
is there a way to determine what the
T
parameter of a specific instance of the annotation obtained from reflection at runtime? Alternately, is there some variation on
Copy code
annotation class Foo<T : Any>(val fooClass: KClass<T> = T::class)
which works? I'm trying to avoid having to write
@Foo<Bar>(Bar::class)
with manual duplication at use sites, but I don't see how to get at the type parameter otherwise.