https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
s

Stylianos Gakis

08/04/2022, 9:55 AM
Looking at the KotlinPoet documentation https://square.github.io/kotlinpoet/ I can’t seem to find how one would generate a function with a generic argument with an upper bound to some type, something like:
Copy code
fun <T : SomeType> foo(param: Bar<T>): Unit {
  asdf(myParam)
}
Is there some part of the docs which I am missing? If so I’d really appreciate any pointers.
m

Matthias Geisler

08/04/2022, 10:22 AM
Maybe this and this helps.
s

Stylianos Gakis

08/04/2022, 10:33 AM
Yes!! I was trying to do this inside the
addParameter(ClassName(...).parameterizedBy(//here))
and I completely missed the
addTypeVariables
function. This is the first time I use KotlinPoet so I am not familiar with the entire API and the mental model of how everything should be hooked up. Thanks a ton for this! I will however still file a bug in the repository to hopefully expand the docs a bit on this, I feel like it does deserve a spot in the samples given in https://square.github.io/kotlinpoet/
m

Matthias Geisler

08/04/2022, 10:58 AM
Maybe file a PR instead with a good example. I think the maintainers are open to that and issue is resolved right away.
s

Stylianos Gakis

08/04/2022, 11:05 AM
That is true, good idea! I will give it a try as soon as possible.
3 Views