I try to add some modifiers to a methodspec but i'm stuck at the parameters. The parameters are from the type Modifier
. The tutorial says that you can just pass Modifier.PUBLIC
but Modifier.PUBLIC
is an Integer value. Am i missing something here? This is my (equal to the tutorial on github) code:
public void generateCode(){
MethodSpec main = MethodSpec.methodBuilder("main")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(void.class)
.addParameter(String[].class, "args")
.addStatement("$T.out.println($S)", System.class, "Hello, JavaPoet!")
.build();
}
You are passing
java.lang.reflect.Modifier.PUBLIC
, which is indeed anint
, but JavaPoet wants ajavax.lang.model.element.Modifier
, which is an enum.