简体   繁体   中英

How to specify the order of parameters in @AllArgsConstructor in lombok

If I have a class like below,

import lombok.AllArgsConstructor;

@AllArgsConstructor
class MyClass{
    private String one;
    private Integer three;  
    private Integer two;   
}

What will be the order of parameters in the generated constructor ? Is it always like below,

public MyClass(String one, Integer three, Integer two) {
    this.one = one;
    this.three = three;
    this.two = two;        
}

I noticed it's the order of declaration in the class itself. But need to confirm it. Couldn't find any documentation that verify that fact.

If not can we define the order of params in anyway ?

The lombok document on Constructor, it says: (the last sentence of the third paragraph. Or you can find 'sort' with your browser's find feature)

The order of the parameters match the order in which the fields appear in your class.

Though the sentence is in the paragraph for @RequiredArgsConstructor , the same rule looks to apply to @AllArgsConstructor , too.

https://projectlombok.org/features/constructor

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