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

时光怂恿深爱的人放手 提交于 2020-03-18 03:42:40

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/49106072/how-to-specify-the-order-of-parameters-in-allargsconstructor-in-lombok

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!