参考Lombok官网学习,中途记录一则。

sequenceDiagram
    loop every day
        A->>B: How are you?
        B->>A: Great!
    end

内容更新进度

2017.09.08 Lombok的基本特性罗列;


What is Lombok?

略。

Using Lombok

版本

目前主要有 1.16.18 Download

Install Build Tools

maven
<dependencies>
	<dependency>
		<groupId>org.projectlombok</groupId>
		<artifactId>lombok</artifactId>
		<version>1.16.18</version>
		<scope>provided</scope>
	</dependency>
</dependencies>
gradle
apply plugin: 'java'
apply plugin: 'nebula.provided-base'

repositories {
	mavenCentral()
}

dependencies {
	provided 'org.projectlombok:lombok:1.16.18'
}

Install IDEs

IntelliJ IDEA
The Jetbrains IntelliJ IDEA editor is compatible with lombok.

Add the Lombok IntelliJ plugin to add lombok support IntelliJ:

Go to File > Settings > Plugins
Click on Browse repositories...
Search for Lombok Plugin
Click on Install plugin
Restart IntelliJ IDEA
MyEclipse

MyEclipse IDE


Features-Stable


val

Finally! Hassle-free final local variables.

  • 代码
      val example = new ArrayList<String>();
    
  • 生成代码
      final ArrayList<String> example = new ArrayList<String>();
    

更详细参照


@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 toString for you!

  • 代码
        
    
  • 生成代码
        
    

更详细参照


@EqualsAndHashCode

Equality made easy: Generates hashCode and equals implementations from the fields of your object..

  • 代码
        
    
  • 生成代码
        
    

更详细参照


@NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructor

Constructors made to order: Generates constructors that take no arguments, one argument per final / non-nullfield, or one argument for every field.

  • 代码
        
    
  • 生成代码
        
    

更详细参照


@Data

All together now: A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, and @Setter on 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!

  • 代码
        
    
  • 生成代码
        
    

更详细参照


@Synchronized

synchronized done 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?”

  • 代码
        
    
  • 生成代码
        
    

更详细参照


Features-Lombok experimental features

Lombok experimental features


你可以参与的

如果您在阅读中发现文中描述有不正确的地方,欢迎留言指正,留言交流或者在关于我加我微信。

我还可以做的

此文作为学习入门文档,如果后续有新的见解或更有帮助的内容,会持续更新。

参考声明

Lombok features
Reducing Boilerplate Code with Project Lombok