在 Java 中,要为多个目标定义注释,可以使用花括号:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD})
public @interface AnnotExample {
String name();
}
但是,这在 Groovy 中不起作用:
$ groovyc AnnotExample.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
AnnotExample.groovy: 8: expecting '}', found ',' @ line 8, column 26.
@Target({ElementType.TYPE, ElementType.FIELD})
^
1 error
如何在 Groovy 中完成此操作?
最佳答案
在 Groovy 中,语法是列表之一 - 即带有方括号:
@Retention(RetentionPolicy.RUNTIME)
@Target([ElementType.TYPE, ElementType.FIELD])
public @interface AnnotExample {
String name()
}
关于groovy - 如何在 Groovy 中为多个目标定义注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30598434/