如何在Groovy中为多个目标定义注释?

时间:2015-06-02 14:07:35

标签: groovy annotations

在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中完成?

1 个答案:

答案 0 :(得分:4)

在Groovy中,语法是列表 - 即使用方括号:

ERROR [2015-06-02 16:05:40Z]: Error while executing command: Start Server
System.ArgumentException: Item has already been added. Key in dictionary: 'JAVA_HOME'  Key being added: 'JAVA_HOME'
   at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
   at System.Collections.Hashtable.Add(Object key, Object value)
   at System.Collections.Specialized.StringDictionaryWithComparer.Add(String key, String value)
   at IBMWorklight.WLCommandExecuter.executeWLCommand(String wlCommand, String executionFolder)
   at IBMWorklight.WLCommandExecuter.init()
   at IBMWorklight.StartServerHandler.Run()
   at MonoDevelop.Components.Commands.CommandHandler.Run(Object dataItem)
   at MonoDevelop.Components.Commands.CommandHandler.InternalRun(Object dataItem)
   at MonoDevelop.Components.Commands.CommandManager.DefaultDispatchCommand(ActionCommand cmd, CommandInfo info, Object dataItem, Object target, CommandSource source)
   at MonoDevelop.Components.Commands.CommandManager.DispatchCommand(Object commandId, Object dataItem, Object initialTarget, CommandSource source)