如何在lombok中的@AllArgsConstructor中指定参数的顺序 [英] How to specify the order of parameters in @AllArgsConstructor in lombok

查看:4003
本文介绍了如何在lombok中的@AllArgsConstructor中指定参数的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个像下面这样的课程,

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 ?

推荐答案

Constructor上的龙目岛文档说:(第三段的最后一句话.或者可以使用浏览器的查找功能查找排序")

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.

尽管句子位于@RequiredArgsConstructor的段落中,但同样的规则也适用于@AllArgsConstructor.

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

https://projectlombok.org/features/constructor

这篇关于如何在lombok中的@AllArgsConstructor中指定参数的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆