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 - Spring Tutorial
From the course: Learning Lombok: Streamlined Java Programming
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Abating setter and getter code bloat4m 52s
-
(Locked)
Adding but reducing ToString, Equals, and HashCode methods4m 22s
-
(Locked)
Pairing down constructor bloat3m 57s
-
(Locked)
One annotation to rule them all5m 20s
-
(Locked)
Playing nicely with Spring @Autowired4m 28s
-
(Locked)
JEP 359 record versus @Data and @Value5m 6s
-
(Locked)
Challenge: Reduce boilerplate code in POJOs3m 29s
-
(Locked)
Solution: Reduce boilerplate code in POJOs5m 23s
-
-
-
-