是否可以将 Lombok 注释用作元注释? [英] Is it possible to use Lombok annotations as a meta-annotation?
问题描述
我想为传输对象定义自己的注释,并在其中包含一些 Lombok 注释作为元注释:
I want to define my own annotation for transfer objects and include there some Lombok annotations as meta-annotations:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Data
@NoArgsConstructor
@AllArgsConstructor
public @interface TransferObject {
}
目的是用 @TransferObject
注释我所有的传输对象并继承"以上所有内容.实际上它不起作用,用 @TransferObject
注释的类不被 Lombok 处理.
The intent is to annotate all my transfer objects with @TransferObject
and "inherit" all of the above. In practice it doesn't work, classes annotated with @TransferObject
are not processed by Lombok.
有什么方法可以让这个工作吗?如果没有,理论上是否可以增强 Lombok 以查找元注释?
Is there some way to get this working? If not, it it theoretically possible to enhance Lombok to look for meta-annotations?
注意:我使用的是 Java 8.
Note: I'm on Java 8.
更新:似乎在 github 上有一个功能请求.
UPDATE: It looks like there's a feature request for this on github.
推荐答案
Short answer is NOT(对于当前版本 1.18.4 - 2018 年 10 月 30 日)
Short answer is NOT (for current version 1.18.4 - Oct 30, 2018)
根据线程这里:
此功能需要在处理的早期阶段进行解决.目前这是不可能的.可能,因为我们现在有了 lombok 配置系统,我们可能会想出一个不同的解决方案.
This feature would require resolution in a very early stage of processing. Currently that is not possible. Possibly, since we now have the lombok configuration system, we might come up with a different solution.
实际上,他们在 Lombok 的 GitHub 页面 - 没有实现.
Actually, they have several requests of the similar functionality on Lombok's GitHub page - non of them is implemented.
这篇关于是否可以将 Lombok 注释用作元注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!