开发者

Dynamic class annotation

I want to annotate a class dynamically to make it the more generic as possible:

public class Test<T> {开发者_Go百科

    @XmlAttribute(name = dynamicvalue)
    T[] data;

    public Test(String dynamicvalue) {
    }  
}

Is there any way to achieve something like this.

TA


No. Annotations are static class-level information and they can't be influenced by the values of instance fields (no, they can't influenced by the values of static fields either).


You can create new classes at runtime by loading in new bytecode, so in theory it should be possible (remember, the annotations are associated with the class, not the object). And you can use an API like Java Assist to help create them. There's an annotation package that you could look at.

It won't be easy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜