@NoArgsConstructer @AllArgsConstructer
时间: 2024-04-27 08:18:18 浏览: 11
@NoArgsConstructor和@AllArgsConstructor是Java中的注解,用于自动生成无参构造函数和全参构造函数。
@NoArgsConstructor注解用于生成一个无参构造函数。当一个类没有定义任何构造函数时,编译器会自动为该类生成一个默认的无参构造函数。但是,如果在类中定义了有参构造函数,编译器就不会再自动生成无参构造函数。使用@NoArgsConstructor注解可以强制编译器生成一个无参构造函数,即使类中已经定义了有参构造函数。
@AllArgsConstructor注解用于生成一个包含所有成员变量的全参构造函数。当一个类中有多个成员变量时,手动编写全参构造函数可能会很繁琐。使用@AllArgsConstructor注解可以简化代码,自动生成一个包含所有成员变量的全参构造函数。
使用这两个注解可以提高代码的可读性和开发效率。
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)