Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy 在注释中访问静态字段_Groovy_Annotations - Fatal编程技术网

Groovy 在注释中访问静态字段

Groovy 在注释中访问静态字段,groovy,annotations,Groovy,Annotations,我试图在Groovy类中使用Java注释,但在将Java类的静态字段设置为参数时遇到困难: 注释:Id.java package x.y.annotations; import java.lang.annotation.ElementType; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Id { public Class<Adapter> adapte

我试图在Groovy类中使用Java注释,但在将Java类的静态字段设置为参数时遇到困难:

注释:Id.java

package x.y.annotations;

import java.lang.annotation.ElementType;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Id {

    public Class<Adapter> adapter();

    public Class<Object> targetType();

    public String targetAttribute();

    public String onDelete();

}
以及出现问题的groovy类:Person.groovy

package x.y.domain

import x.y.annotations.Id
import x.y.static.domain.XPerson

class Person {

    @Id(adapter = Adapter, targetType = XPerson, targetAttribute = XPerson.ID, onDelete = "delete")
    long id
}
Eclipse将“targetAttribute=XPerson.ID”部分标记为:

Groovy:预期“x.y.domain.XPerson.ID”是java.lang.String类型的内联常量,而不是@x.y.annotations.ID中的属性表达式

我还尝试了“XPerson@ID”或为ID字段定义getter之类的方法,但没有任何帮助

任何提示都很好

问候,,
michael

注释值只能在编译时使用。将字段设置为最终。(需要注意的是,该字段不能像代码片段所暗示的那样在静态初始值设定项中初始化。)

我在Groovy JIRA中发现了一个相关问题。这是一只虫子。应该有用。参见

嗨,到底什么“应该有效”?因为它仍然是一个bug。问题中描述的内容应该可以工作,但实际上不行,因为groovy有一个bug
package x.y.domain

import x.y.annotations.Id
import x.y.static.domain.XPerson

class Person {

    @Id(adapter = Adapter, targetType = XPerson, targetAttribute = XPerson.ID, onDelete = "delete")
    long id
}