在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()
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句