jean
03/11/2023, 10:16 AMemptyList()
to .defaultValue("%L", defaultValue)
but it generate an array instead : public val myList: List<String> = []
which fails. How can I fix it to generate public val myList: List<String> = emptyList()
instead?Chrimaeon
03/11/2023, 10:54 AMdefaultValue
that you pass to the method?jean
03/11/2023, 11:08 AMval defaultValue: List<String> = emptyList<String>()
ParameterSpec.builder(
name = "myList",
type = List::class.java.asClassName()
.parameterizedBy(String::class.java.asClassName())
)
.defaultValue("%L", defaultValue)
.build()
Chrimaeon
03/11/2023, 11:14 AMMemberName
to get a reference to a function/member. what your code is doing is evaluate emptyList
and put that value as a literal. See https://square.github.io/kotlinpoet/#m-for-members
What you need is
val emptylist = MemberName("kotlin.collections", "emptylist")
ParameterSpec.builder("myList", List::class.parameterizedBy(String::class))
.defaultValue("%M()", emptylist)
.build()
jean
03/11/2023, 11:43 AM