Why Project Lombok is useful for java programmer?
Lombok is a tool that generates code for you, but not in the way that
your IDE generates it. Your IDE generates getters & setters, or
equals and more, and then puts the code in your uncompiled class file.
Lombok generates the same thing, but does it in the class file; all you
need to do is add some annotations like @Setter, @Getter, @Builder, @Data
… to your code and Lombok generates the setters, getters and so on for
you. At the same time, you can override whatever is generated by just
writing the method yourself instead.
Lombok features/Advantages
val- Finally! Hassle-free final local variables.
@NonNull- or: How I learned to stop worrying and love the NullPointerException.
@Cleanup- Automatic resource management: Call your
close()methods safely with no hassle. @Getter/@Setter- Never write
public int getFoo() {return foo;}again. @ToString- No need to start a debugger to see your fields: Just let lombok generate a
toStringfor you! @EqualsAndHashCode- Equality made easy: Generates
hashCodeandequalsimplementations from the fields of your object. @NoArgsConstructor,@RequiredArgsConstructorand@AllArgsConstructor- Constructors made to order: Generates constructors that take no arguments, one argument per final / non-null field, or one argument for every field.
@Data- All together now: A shortcut for
@ToString,@EqualsAndHashCode,@Getteron all fields, and@Setteron all non-final fields, and@RequiredArgsConstructor! @Value- Immutable classes made very easy.
@Builder- ... and Bob's your uncle: No-hassle fancy-pants APIs for object creation!
@SneakyThrows- To boldly throw checked exceptions where no one has thrown them before!
@Synchronizedsynchronizeddone right: Don't expose your locks.@Getter(lazy=true)- Laziness is a virtue!
@Log- Captain's Log, stardate 24435.7: "What was that line again?"
- Configuration system
- Lombok, made to order: Configure lombok features in one place for your entire project or even your workspace.
- Experimental features
- Here be dragons: Extra features which aren't quite ready for prime time yet.
No comments:
Post a Comment