Roukanken
05/19/2022, 1:56 PMI wonder if there’s a way to preventI don't think there is a way to prevent it compile time, but you can always just half-botch it by having the assert always fail whenif the generic type of the function has its own generic typeisA
T::class.typeParameters
is non-empty (eg, the reified class has some generic parameters on it's own)christophsturm
05/19/2022, 2:12 PMRoukanken
05/19/2022, 2:13 PMRoukanken
05/19/2022, 2:26 PMRoukanken
05/19/2022, 2:29 PMinline fun <reified T> test() = T::class.typeParameters.map { it.name }
test<Collection<String>>()
gives you ["E"]
robfletcher
05/19/2022, 5:01 PMEric
05/19/2022, 6:26 PMRoukanken
05/19/2022, 6:28 PMisA<List<*>>()
to work tho 🤔
can you distinguish between those two? I don't think you do even that...robfletcher
05/19/2022, 6:28 PMEric
05/19/2022, 6:28 PM[E]
for *
as wellrobfletcher
05/19/2022, 6:29 PMEric
05/19/2022, 6:31 PMvariance
is always out
, name
is always [E]
and upperBounds
is always kotlin.Any?
christophsturm
05/19/2022, 6:31 PMchristophsturm
05/19/2022, 6:32 PMisAWildcard
that allows wildcardschristophsturm
05/19/2022, 6:33 PMEric
05/19/2022, 6:33 PMchristophsturm
05/19/2022, 6:33 PMEric
05/19/2022, 6:36 PMisA
could have a ignoreGenerics: Boolean = false
parameter for when you want isA<List<*>>(ignoreGenerics = true)
to pass, although that feels a little clunkyrobfletcher
05/19/2022, 6:36 PMchristophsturm
05/19/2022, 6:37 PMchristophsturm
05/19/2022, 6:54 PMEric
05/19/2022, 6:57 PMchristophsturm
05/19/2022, 6:58 PMEric
05/19/2022, 6:58 PMchristophsturm
05/19/2022, 6:59 PM