Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants