@RequiredArgsConstructor
时间: 2023-10-12 09:13:34 浏览: 26
`@RequiredArgsConstructor` is a Lombok annotation that generates a constructor with the required final fields as arguments. This annotation can be used to reduce boilerplate code when creating constructors for classes with many final fields.
For example, consider the following class:
```
public class Person {
private final String firstName;
private final String lastName;
private final int age;
}
```
Using `@RequiredArgsConstructor`, Lombok will generate the following constructor for the class:
```
@RequiredArgsConstructor
public class Person {
private final String firstName;
private final String lastName;
private final int age;
}
```
This constructor takes in the three final fields as arguments and assigns them to their respective fields. This reduces the amount of boilerplate code needed to create the constructor.