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

If I have a class as shown below,

import lombok.AllArgsConstructor;

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

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

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

I noticed this is the declaration order in the class itself. But you need to confirm this. Could not find documentation confirming this fact.

Should we not be able to determine the order of the parameters anyway?

+4
source share
1 answer

A lombok document on the Constructor, it says: (last sentence of the third paragraph. Or you can find a "sort" with a search function in the browser)

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

Although the sentence is in the paragraph for @RequiredArgsConstructor, the same rule applies to @ AllArgsConstructor.

https://projectlombok.org/features/constructor

+3

Source: https://habr.com/ru/post/1694457/


All Articles