I use JavaPoet to create Java code. I defined the following array:
String[] testArr = new String[] {"1","2"};
and a constructor:
ArrayTypeName stringArray = ArrayTypeName.of(String.class);
MethodSpec constroctMethod = MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addStatement("$T names", stringArray)
.addStatement("names = $N", testArr)
.build();
The former does not work. I want to create the statement:
String[] names = new String[] {"1","2"};
How can I assign an Array to a Statement like in the previous line?