简体   繁体   中英

Are static variables included in lombok AllArgsConstructor annotation?

The title pretty much sums it up. I'm wondering if I need to include static variables (which I probably don't) in the constructor.

Given that static variables are static I probably dont. But I didnt find any answers to this question on stackoverflow.

No static fields are skipped while using these lombok annotations

@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor

Static fields are skipped by these annotations.

If you want to declare constructor with static fields then you can declare the one explicitly, but you might end up with compiler error if any of those constructors have same signature

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.

The answer is no as you can check in javadoc:

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

or official documentation: https://projectlombok.org/features/Constructor

RequiredArgsConstructor includes in the constructor all final fields. However, you cannot have a static final variable not initialized (as they can be used even with no instance of that class)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM