Open
Description
I want to add a nullable property to an enum. This doesn't currently work using the format function becuase the arg elements are not declared as nullable.
TypeSpec.enumBuilder("Sample")
.primaryConstructor(
FunSpec.constructorBuilder()
.addParameter(
ParameterSpec.builder(
"myNullableString",
String::class.asTypeName().copy(nullable = true)
).build()
)
.build()
)
.addEnumConstant(
name = "Rock",
typeSpec = TypeSpec.anonymousClassBuilder()
.addSuperclassConstructorParameter("%S", "Hello")
.build()
)
.addEnumConstant(
name = "Paper",
typeSpec = TypeSpec.anonymousClassBuilder()
.addSuperclassConstructorParameter("%S", null) // <-- this doesn't compile
.addSuperclassConstructorParameter(CodeBlock.of("%S", null)) // <-- workaround
.build()
)
.build()
Activity