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.
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Project Lombok!
2. 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.)
3. 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.
4. Features
@Getter, @Setter, @ToString, @EqualsAndHashCode, @Data
@NoArgsConstructor, @RequiredArgsConstructor and
@AllArgsConstructor
@Cleanup, @Synchronized
@Log
@Delegate
val
5. @Getter and @Setter
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
8. Constructor level Annotations
@NoArgsConstructor, @RequiredArgsConstructor, @AllA
rgsConstructor
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
9. @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
10. @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();
12. 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/
Notes de l'éditeur
@Getter / @SetterNever write public intgetFoo() {return foo;} again.@ToStringNo need to start a debugger to see your fields: Just let lombok generate a toString for you!@EqualsAndHashCodeEquality made easy: Generates hashCode and equals implementations from the fields of your object.@DataAll together now: A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, and @Setter on all non-final fields, and @RequiredArgsConstructor!@NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructorConstructors made to order: Generates constructors that take no arguments, one argument per final / non-null field, or one argument for every field.@CleanupAutomatic resource management: Call your close() methods safely with no hassle.@Synchronizedsynchronized done right: Don't expose your locks.@LogCaptain's Log, stardate 24435.7: "What was that line again?"@DelegateDon't lose your composition.valFinally! Hassle-free final local variables.