lombok AllArgsConstructor 注释中是否包含静态变量?

Are static variables included in lombok AllArgsConstructor annotation?

标题几乎概括了它。我想知道我是否需要在构造函数中包含静态变量(我可能不需要)。

鉴于静态变量是静态的,我怀疑它们可能不是。但是我没有在Whosebug上找到这个问题的任何答案。

使用这些 lombok 注释时不会跳过任何静态字段

@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor

Static fields are skipped by these annotations.

如果你想用静态字段声明构造函数,那么你可以显式声明它,但如果这些构造函数中的任何一个具有相同的签名,你可能会以编译器错误告终

Unlike most other lombok annotations, the existence of an explicit constructor does not stop these annotations from generating their own constructor. This means you can write your own specialized constructor, and let lombok generate the boilerplate ones as well. If a conflict arises (one of your constructors ends up with the same signature as one that lombok generates), a compiler error will occur.

答案是否定的,因为您可以查看 javadoc:

An all-args constructor requires one argument for every field in the class.

或官方文档:https://projectlombok.org/features/Constructor

RequiredArgsConstructor 在构造函数中包含所有 final 字段。但是,您不能让 static final 变量未初始化(因为即使没有 class 的实例也可以使用它们)