project lombok!
DESCRIPTION
The introduction of Project Lombok, a combination compile-time and development-time code generator, has made Java POJO verbosity history. Add Lombok to your daily coding practices, and you won't go back.TRANSCRIPT
![Page 1: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/1.jpg)
Project Lombok
Spices up your java!
Mehdi Hassan
Team Lead
Etilize Pvt. Ltd.(GfK)
![Page 2: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/2.jpg)
Problems of the Industry
Boiler Plate Code
Syntax Verbosity
Non Standardization
Not following the standard code conventions!!
Human Error/Dependency
Repeatable things (defining Getters, Setters etc.)
Project Lombok!
![Page 3: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/3.jpg)
Demo Video
Taken from http://projectlombok.org/
Gives an idea what Project Lombok is and how it can be installed.
Simple Demo of few Features.
Project Lombok!
![Page 4: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/4.jpg)
Features
@Getter, @Setter, @ToString, @EqualsAndHashCode, @Data
@NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructor
@Cleanup, @Synchronized
@Log
@Delegate
val
Project Lombok!
![Page 5: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/5.jpg)
@Getter and @Setter
Project Lombok!
Automatic Generation of getters and setters.
Method will be public unless you explicitly specify an AccessLevel
@Getter and/or @Setter annotation on class
Disable getter/setter generation for any field by using the special AccessLevel.NONE
@NotNull for nullity check
Demo
![Page 6: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/6.jpg)
@ToString
Project Lombok!
Generates a default implementation of the toString() method
Parameters
Demo
![Page 7: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/7.jpg)
@EqualsAndHashCode
Generates hashCode and equals implementations from the fields (non-static, non-transient)
Parameters
Demo
Project Lombok!
![Page 8: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/8.jpg)
Constructor level Annotations
@NoArgsConstructor, @RequiredArgsConstructor, @AllArgsConstructor
Generates constructors that take no arguments, one argument per final / non-null field, or one argument for every field.
Specialized constructor can be made. Compile-time error in case of any conflicts.
Demo
Project Lombok!
![Page 9: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/9.jpg)
@Data
All together now: A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, @Setter on all non-final fields, and @RequiredArgsConstructor
Included annotations with changed parameters can be defined along with @Data
Project Lombok!
![Page 10: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/10.jpg)
@Cleanup
Automatic resource management: Call your close() methods safely with no hassle.
Example: @Cleanup InputStream in = new FileInputStream("some/file");
If the type of object you'd like to cleanup does not have a close() method, but some other no-argument method like dispose() so write it as
@Cleanup("dispose") TestClass t = new TestClass();
Project Lombok!
![Page 11: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/11.jpg)
Logger Annotations!
Generate a logger field with name “log”
Four options
@CommonsLog
@Log
@Log4j
@Slf4j
Project Lombok!
![Page 12: Project Lombok!](https://reader033.vdocuments.net/reader033/viewer/2022061214/5499a563b47959a66e8b45a6/html5/thumbnails/12.jpg)
And Lot More!!!
Some other supported features like @Delegate, @Synchronized, val etc.
More to come soon!
Open Source
Details can be found at http://projectlombok.org/
Project Lombok!