注释可以用于code注射液? [英] Can annotations be used for code injection?
问题描述
我意识到,这可能是已被要求,并回答了一个问题,但是请多多包涵。
I realise that this might be a question that has been asked and answered, but please bear with me.
我想知道是否可以使用注释注入code到您的类编译时间。典型的例子是为您的对象的成员一个getter和setter。这不正是我需要它,但它足以说明其基本思想。
I want to know if it is possible to use annotations to inject code into your classes compile time. The classic example is to generate a getter and setter for the members of your object. This is not exactly what I need it for, but it serves to illustrate the basic idea.
现在互联网上的基本答案,我得到的是否定的,但是这家伙做到了:
Now on the internet the basic answer I get is no, but this guy did it:
有谁知道他怎么做他做什么(如果他实际上做他做什么,他说)?
Does anyone know how he does what he does (and if he actually does what he says he does)?
最主要的是,他不使用注释处理器生成一个新的Java文件进行编译。这种技术我知道的,也不会为我们的目的工作。
The main thing is that he does not use an annotation processor to generate a new java file to compile. This technique I am aware of and will not work for our purpose.
感谢
推荐答案
它不支持在编译时修改code,但它似乎使用不支持的javac内部的API是可能的,的这里是一个后引用hanbuy-panno溶液还链接到<一个href=\"http://svntrac.hanhuy.com/repo/browser/hanhuy/trunk/panno/src/com/hanhuy/panno/processing/PropertyProcessor.java\"相对=nofollow> code ...
It is not supported to modify code at compile time but it seems to be possible by using non-supported javac-internal APIs, here is a post referencing the hanbuy-panno solution with also a link to the code...
这篇关于注释可以用于code注射液?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!