在我目前的项目中,我有这段代码:
for(Annotation annotation : field.getAnnotations()) {
String package = annotation.annotationType().getPackage().getName();
if(package.equals("com.loja.annotations.input_type"))
input.setAttribute("type", annotation.annotationType().getSimpleName());
}
当我尝试构建项目时,由于此错误,此代码导致编译失败:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project store: Compilation failure: Compilation failure:
[ERROR] /c:/Users/Kleber Mota/Documents/GitHub/app/src/main/java/com/loja/thymeleaf/processor/form/InputProcessor.java:[37,11] not a statement
[ERROR] /c:/Users/Kleber Mota/Documents/GitHub/app/src/main/java/com/loja/thymeleaf/processor/form/InputProcessor.java:[37,17] ';' expected
[ERROR] /c:/Users/Kleber Mota/Documents/GitHub/app/src/main/java/com/loja/thymeleaf/processor/form/InputProcessor.java:[38,14] illegal start of expression
[ERROR] /c:/Users/Kleber Mota/Documents/GitHub/app/src/main/java/com/loja/thymeleaf/processor/form/InputProcessor.java:[38,21] illegal start of expression
[ERROR] /c:/Users/Kleber Mota/Documents/GitHub/app/src/main/java/com/loja/thymeleaf/processor/form/InputProcessor.java:[38,28] ';' expected
[ERROR] /c:/Users/Kleber Mota/Documents/GitHub/app/src/main/java/com/loja/thymeleaf/processor/form/InputProcessor.java:[38,22] variable declaration not allowed here
任何人都可以看到这里有什么问题?
第37行是:String package = annotation.annotationType().getPackage().getName();
,第38行是if(package.equals("com.loja.annotations.input_type"))
答案 0 :(得分:0)
你可以试试这个..
annotation.annotationType().getName();
答案 1 :(得分:0)
您可以在第37行(之前的if)之后打印出“package”变量。 我编写并运行了类似的代码,它对我有用。我在api包中创建了一个自定义注释,第37行返回“api”。