Adding KModifier
for interface type parameter.
#1208
-
Hi! Somewhere in the code, I have interfaces: interface Base
interface BaseProvider {
fun list(): List<out Base>
} now using kotlin poet, I'd like to create an implementation of List::class.parameterizedBy(
Base::class // <- how do I add a modifier KModifier.OUT
) One thing I tried is to "abuse" List::class.asClassName().parameterizedBy(
TypeVariableName(T::class.qualifiedName.toString(), KModifier.OUT)
) but in this case, the modifier is stripped and the results of the two snippets are equivalent. Is there a mechanism or a workaround to variance in such cases? |
Beta Was this translation helpful? Give feedback.
Answered by
Egorand
Jan 28, 2022
Replies: 1 comment 2 replies
-
What you're looking for is probably something along the lines of: List::class.asClassName().parameterizedBy(
WildcardTypeName.producerOf(Base::class.asTypeName())
) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
vnermolaev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What you're looking for is probably something along the lines of: