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.

Simplify final local variable declaration

Simplify final local variable declaration - Spring Tutorial

From the course: Learning Lombok: Streamlined Java Programming

Simplify final local variable declaration

- [Instructor] With IntelliJ Project code open to 02-03 begin LombokDemo, open the EmployeeService.java in the service package. Oftentimes in Java, we have an annoying process of repeating ourselves over and over again by typing out long variable names, types, et cetera. If we look at the employee service file, we see in our methods how we repeatedly instantiate these local variables to receive a final collection of employees. Lombok offers a shortcut, hassle-free final local variable with the keyword val. Now, this will only work with local variables, but this can be a time saver. Inside the findemployee method, we're going to replace final list employee with val, ensure that you choose the lombok type. If we open projectlombok.org/features/val documentation, it reads, you can use the val as a type of local variable declaration instead of actually writing the type. When you do this, the type will be inferred from the…

Contents