gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:06:43 25 4
gpt4 key购买 nike

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

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

最佳答案

使用这些 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.

关于java - lombok AllArgsConstructor 注释中是否包含静态变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58156766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com