[英]IncompleteAnnotationException when accessing an annotation in groovy
I defined an annotation as follows 我定义了一个注释如下
import java.lang.annotation.ElementType
import java.lang.annotation.Inherited
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import java.lang.annotation.Target
/**
* Annotation for any object that exposed a remote interface
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Remote {
String label()
}
and i'm trying to use it this way 我正在尝试以这种方式使用它
import com.yascie.annotation.Remote
@Remote("Bar")
class Foo {
String name
String value
static String code
}
I keep getting though an error saying that the annotation is missing element label 我不断收到错误消息,指出注释缺少元素标签
java.lang.annotation.IncompleteAnnotationException: Remote missing element label
Now when i tried to inspect the annotation object i can see that a label method is available trough a proxy but i can't access it. 现在,当我尝试检查注释对象时,我可以看到通过代理可以使用标签方法,但是我无法访问它。 Any ideas ? 有任何想法吗 ?
Remote annotation = objectClass.clazz.getAnnotation(Remote.class);
annotation.metaClass.methods.each {println it}
public final java.lang.String $Proxy14.label()
You have two options. 您有两个选择。 If you want to use the @Remote("Bar")
syntax then you need to change the label()
method to value()
since that's the method name for the default property for annotations when the name isn't specified. 如果要使用@Remote("Bar")
语法,则需要将label()
方法更改为value()
因为这是未指定名称时注释的默认属性的方法名称。
If you want it to be called label()
though, specify it as @Remote(label="Bar")
如果您希望将其称为label()
,则将其指定为@Remote(label="Bar")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.