实践Lombok

Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Never write another getter or equals method again. Early access to future java features such as val, and much more.

1
2
3
4
5
<dependency>
	<groupId>org.projectlombok</groupId>
	<artifactId>lombok</artifactId>
	<version>1.14.4</version>
</dependency>

javac

1
$ javac -cp lombok.jar MyCode.java

Eclipse

install lombok plug-in

1
$ java -jar lombok-1.18.6.jar

或者

first copy lombok-1.18.6.jar to Eclipse installation directory, then edit the eclipse.init file and add the following entry: -javaagent:lombok.jar-vmargs -javaagent:lombok.jar

IntelliJ IDEA

install lombok plug-in

Required IntelliJ Configuration

In your project Settings: Click Build, Execution, Deployment -> Compiler, Annotation Processors. Click Enable Annotation Processing

Afterwards you might need to do a complete rebuild of your project via Build -> Rebuild Project.

注解

@Data

@Getter

@Setter

@AllArgsConstructor

@NoArgsConstructor

@Slf4j

1
2
3
4
5
6
@Slf4j
public class TestMain {
  public void static main(String[] args) {
    log.info("直接使用log记录日志");
  }
}