Back to Java

See Alse Lombok Annotations Support for VS Code



1. Features

1.1. @ToString

No need to start a debugger to see your fields: Just let lombok generate a toString for you!

import lombok.ToString;

@ToString(callSuper=true, onlyExplicitlyIncluded = true)
public class MyBean {
  public final String name;
  public final float value;

1.2. @Data

All together now: A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, and @Setter on all non-final fields, and @RequiredArgsConstructor!

1.3. @Builder

@Builder lets you automatically produce the code required to have your class be instantiable with code such as: Person.builder().name("Adam Savage").city("San Francisco").job("Mythbusters").job("Unchained Reaction").build();

1.4. @Slf4j

import lombok.extern.slf4j.Slf4j;

public class CompositeServiceTest {
  public void testSomething() throws JsonProcessingException {
    Query query = queryService.getQuery("related-enterprises-summary");
    Object resp = compositeService.doSomething(query.getParams());"resp={}", JSON.toJSONString(resp));

1.5. @Accessors A more fluent API for getters and setters.

@Accessors was introduced as experimental feature in lombok v0.11.0.


import lombok.experimental.Accessors;
@Accessors(chain = true)
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;

User user = new User().setId(1L).setEmail("ab@c.c");

2. Reference

MainWiki: Lombok (last edited 2018-12-22 00:45:29 by twotwo)