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 - 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…
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
-
-
-
-
Lombok implements a builder design pattern4m 55s
-
(Locked)
Simplifying null checks and removing bloat3m 58s
-
(Locked)
Simplify final local variable declaration4m 40s
-
(Locked)
Mutable local variables versus JEP 286 var4m 22s
-
(Locked)
Mutable setters using Lombok @With4m 17s
-
(Locked)
Challenge: Utilizing simplified Lombok POJOs3m 41s
-
(Locked)
Solution: Utilizing simplified Lombok POJOs8m 19s
-
-
-