From the course: Learning Lombok: Streamlined Java Programming

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Pairing down constructor bloat

Pairing down constructor bloat

- [Instructor] Opening up IntelliJ to project 01_03_begin, LombokDemo. Let's think about other code bloat that we can pair down. Looking again at our employee class, we've already removed quite a bit of code bloat through this class, but we can pair it down further with a couple of other annotations that Project Lombok provides. Let's take a quick look at what these annotations do. The three constructor annotations provided by Project Lombok are the @NoArgsConstructor, which is the same as the default constructor. We also have the @Required constructor, which provides a parameter for each field that requires special handling. And the last is the AllArgsConstructor, which builds a constructor with a parameter for each field in your class. I want to take a look a bit closer at these. When using the @NoArgsConstructor, it will generate a compiled time error if the fields are marked final. Now, you can get around this…

Contents