I am stuck on this feature, below is the expected code to be generated, and the total number of parameters is not a fix number, there might be 2, or 3 or more.
val instance: InstanceType = Instance(parameter1, parameter2)
this is within one function, so I only know that I should use .addCode(CodeBlock.of("%L", PropertySpec))
But I don't find a way to define the code block with a dynamic parameters need to be passed in. Any suggestion?
There are two ways to solve this. First,
CodeBlock
has aBuilder
which allows you to construct it dynamically. Here's an example:Second, you can create a separate
CodeBlock
for each parameter and join them: