如何在lombok中的@AllArgsConstructor中指定参数的顺序

编程入门 行业动态 更新时间:2024-10-26 01:31:07
本文介绍了如何在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.

projectlombok/features/constructor

更多推荐

如何在lombok中的@AllArgsConstructor中指定参数的顺序

本文发布于:2023-11-27 20:56:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639571.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   参数   如何在   AllArgsConstructor   lombok

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!