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.

Mutable setters using Lombok @With

Mutable setters using Lombok @With

- [Instructor] With project file 02 05, begin Lombok loaded in IntelliJ. Let's dig into some other issues that we can run into with immutable classes and how we can overcome these with the @with annotation. Let's go ahead and navigate to our employee DTO record and examine a code sample, or we might think about implementing this scenario. Looking at the employee DTO record, we already understand that this class is implicitly immutable because it's a record, and we see some fields that are marked non-null. This forces whoever might use this object to ensure that those particular fields are not null, and that really makes sense, right? Since we expect an employee type record to have at least a first name, a last name, possibly email, and a status, typically the names do not change but the employee status is another matter. If we're passing this employee DTO record around, we probably are going to have a functional business…

Contents