开发者

What's the rationale behind annotations implementing java.lang.reflect.Proxy?

It is not required by the language specification开发者_运维知识库 and seems to be vendor-specific.

Are there any benefits or better guarantees about how will annotations work for the user of the annotation/class? Or is it just that some JDK class got reused to help implementing annotations because it was "convenient"?

See also this IKVM blog post.


Annotations are interfaces. At the same time, they supposed to have some properties at least, which should be read by annotation processors. The easiest way to achieve this duality is to dynamically proxify the annotations at runtime (or may be classloading time, not sure).


The alternative would be to compile (or somehow else generate) a new implementation class for each annotation type, or reinvent another Proxy-like mechanism.

Since the implementation is quite simple (and not really specific to each annotation type), using Proxy objects together with a generic InvocationHandler implementation is a quite good idea.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜