Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example error #900

Open
ZhanChaoHan opened this issue May 10, 2022 · 1 comment
Open

example error #900

ZhanChaoHan opened this issue May 10, 2022 · 1 comment

Comments

@ZhanChaoHan
Copy link

1.When I copy these codes:
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();

		TypeSpec helloWorld = TypeSpec.classBuilder("HelloWorld")
		    .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
		    .addMethod(main)
		    .build();

		JavaFile javaFile = JavaFile.builder("com.example.helloworld", helloWorld)
		    .build();

		javaFile.writeTo(System.out);

2.The editor appears:The method addModifiers(Modifier...) in the type TypeSpec.Builder is not applicable for the arguments (int, int)

@tbroyer
Copy link
Collaborator

tbroyer commented May 10, 2022

You probably didn't import the correct Modifier class. You need javax.lang.model.element.Modifier, not java.lang.reflect.Modifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants