什么语法`@__()`在Lombok中意味着什么? [英] What does the syntax `@__()` mean in Lombok?

查看:218
本文介绍了什么语法`@__()`在Lombok中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在与Lombok合作并积极使用2个月。使用Java我更熟悉一点。但是,我第一次面对语言中的以下语法结构:

I have been working with and actively using Lombok for 2 months. With Java I'm a little more familiar. But, for the first time, I was faced with the following syntax structure in the language:

@RequiredArgsController(onController = @__(@Autowired))
                                       ^^^

这是什么意思,它是怎么回事得到编译?

What does that mean, and how does it get compiled?

推荐答案

这是一个实验性的Lombok语法,创建用于在引用多个注释时支持一个间接层,而不是使用一个类<?> []

This is an experimental Lombok syntax, created to support a layer of indirection when referencing multiple annotations, rather than use a Class<?>[].


语法有点奇怪;要使用3 onX 功能中的任何一个,必须将注释包装到 @__(@ AnnotationGoesHere)中的构造函数/ method /参数中。 。要应用多个注释,请使用 @__({@ Annotation1,@ Annotation2})。注释本身也可以显示参数。

The syntax is a little strange; to use any of the 3 onX features, you must wrap the annotations to be applied to the constructor / method / parameter in @__(@AnnotationGoesHere). To apply multiple annotations, use @__({@Annotation1, @Annotation2}). The annotations can themselves obviously have parameters as well.

https://projectlombok.org/features/experimental/onX.html

来自Lombok开发人员的解释 Roel Spilker

An explanation from Lombok developer Roel Spilker:


原因是javac已经在解析阶段解析了注释,并且如果它可以确定注释无效则会给出错误。通过使用不存在的注释 @__ ,它无法确定它是否为伪造(它可能由注释处理器创建)并且不会立即给出错误。这使得Lombok有时间完成工作并从代码中删除 @__

The reason for it is that javac already resolves annotations in the parsing phase, and gives errors if it can determine that the annotations are invalid. By using a non-existent annotation @__ it cannot determine it is bogus (it might be created by an annotation processor) and will not give an error right away. That gives Lombok the time to do its work and remove the @__ from the code.

这篇关于什么语法`@__()`在Lombok中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆