3

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.PUBLICbut 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();
}
LaaKii
  • 95
  • 10
  • `Modifer.PUBLIC` is not an `int`. It's of type `Modifier`, look here: http://docs.oracle.com/javase/6/docs/api/javax/lang/model/element/Modifier.html?is-external=true – Sweeper Aug 29 '17 at 09:29

1 Answers1

4

You are passing java.lang.reflect.Modifier.PUBLIC, which is indeed an int, but JavaPoet wants a javax.lang.model.element.Modifier, which is an enum.

Hugues M.
  • 17,453
  • 5
  • 27
  • 56