IntelliJ IDEA 中配置lombok插件,编写简略风格Java代码
1.打开IDEA的Settings面板,并选择Plugins选项,然后点击 “Browse repositories..”

2.开启注释处理

3.在pom.xml中添加lombox
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
</dependency>
Demo:
package com.qhong; import lombok.*;
import lombok.extern.slf4j.Slf4j;
import java.io.ByteArrayInputStream;
import java.io.*;
import java.util.ArrayList; @Data
@Slf4j
@AllArgsConstructor
public class Something { private String name;
private final String country;
private final Object lockObj = new Object(); public void sayHello(@NonNull String target) {
String content = String.format("hello,%s", target);
System.out.println(content);
log.info(content);
} public void addBalabala() {
val list = new ArrayList<String>();
list.add("haha");
System.out.println(list.size());
} @SneakyThrows(IOException.class)
public void closeBalabala() {
@Cleanup InputStream is = new ByteArrayInputStream("hello world".getBytes());
System.out.println(is.available());
} @Synchronized("lockObj")
public void lockMethod() {
System.out.println("test lock method");
}
}
看结构:

可以发现,黄色的全是自动生成的
上面简化版的类等效于:
package com.qhong; /**
* Created by qhong on 2017/6/7.
*/
import java.beans.ConstructorProperties;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import lombok.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; public class Something {
private static final Logger log = LoggerFactory.getLogger(Something.class);
private String name;
private final String country;
private final Object lockObj = new Object(); public void sayHello(@NonNull String target) {
if(target == null) {
throw new NullPointerException("target");
} else {
String content = String.format("hello,%s", new Object[]{target});
System.out.println(content);
log.info(content);
}
} public void addBalabala() {
ArrayList list = new ArrayList();
list.add("haha");
System.out.println(list.size());
} public void closeBalabala() {
try {
ByteArrayInputStream $ex = new ByteArrayInputStream("hello world".getBytes()); try {
System.out.println($ex.available());
} finally {
if(Collections.singletonList($ex).get(0) != null) {
$ex.close();
} } } catch (IOException var6) {
throw var6;
}
} public void lockMethod() {
Object var1 = this.lockObj;
synchronized(this.lockObj) {
System.out.println("test lock method");
}
} public String getName() {
return this.name;
} public String getCountry() {
return this.country;
} public Object getLockObj() {
return this.lockObj;
} public void setName(String name) {
this.name = name;
} public boolean equals(Object o) {
if(o == this) {
return true;
} else if(!(o instanceof Something)) {
return false;
} else {
Something other = (Something)o;
if(!other.canEqual(this)) {
return false;
} else {
label47: {
String this$name = this.getName();
String other$name = other.getName();
if(this$name == null) {
if(other$name == null) {
break label47;
}
} else if(this$name.equals(other$name)) {
break label47;
} return false;
} String this$country = this.getCountry();
String other$country = other.getCountry();
if(this$country == null) {
if(other$country != null) {
return false;
}
} else if(!this$country.equals(other$country)) {
return false;
} Object this$lockObj = this.getLockObj();
Object other$lockObj = other.getLockObj();
if(this$lockObj == null) {
if(other$lockObj != null) {
return false;
}
} else if(!this$lockObj.equals(other$lockObj)) {
return false;
} return true;
}
}
} protected boolean canEqual(Object other) {
return other instanceof Something;
} public int hashCode() {
boolean PRIME = true;
byte result = 1;
String $name = this.getName();
int result1 = result * 59 + ($name == null?0:$name.hashCode());
String $country = this.getCountry();
result1 = result1 * 59 + ($country == null?0:$country.hashCode());
Object $lockObj = this.getLockObj();
result1 = result1 * 59 + ($lockObj == null?0:$lockObj.hashCode());
return result1;
} public String toString() {
return "Something(name=" + this.getName() + ", country=" + this.getCountry() + ", lockObj=" + this.getLockObj() + ")";
} @ConstructorProperties({"name", "country"})
public Something(String name, String country) {
this.name = name;
this.country = country;
}
关于lombok的更多语法特性请参考: features
http://www.cnblogs.com/softidea/p/5960182.html
IntelliJ IDEA 中配置lombok插件,编写简略风格Java代码的更多相关文章
- IDEA里面添加lombok插件,编写简略风格Java代码(转)
文章转自http://blog.csdn.net/hinstenyhisoka/article/details/50468271 在 java平台上,lombok 提供了简单的注解的形式来帮助我们消除 ...
- IDEA里面添加lombok插件,编写简略风格Java代码
在 java平台上,lombok 提供了简单的注解的形式来帮助我们消除一些必须有但看起来很臃肿的代码, 比如属性的get/set,及对象的toString等方法,特别是相对于 POJO; 关于lomb ...
- IDEA中的lombok插件安装以及各注解的详细介绍
IDEA中的lombok插件安装以及各注解的详细介绍 其实对于我们来说, 写好实体类后,直接用快捷方式生成get,set方法,还有 构造方法就行了,但是对于字段比较多的, 如果修改一个属性的话,就要再 ...
- 如何在IntelliJ IDEA中使用.ignore插件忽略不必要提交的文件
如何在IntelliJ IDEA中使用.ignore插件忽略不必要提交的文件 最近初学Git,而且在使用的IDE是IntelliJ IDEA,发现IDEA在提交项目到本地仓库的时候,会把.idea文件 ...
- 订阅 如何在IntelliJ IDEA中使用.ignore插件忽略不必要提交的文件
如何在IntelliJ IDEA中使用.ignore插件忽略不必要提交的文件 标签: idea git 插件 分类: Git 最近初学Git,而且在使用的IDE是IntelliJ IDEA,发现IDE ...
- 在 IntelliJ IDEA 中配置 JSF 开发环境的入门详解
JSF 作为 JavaEE 官方标准,在了解并掌握其基本开发技术后,对于功能要求较高.业务流程复杂的各种现代 Web 应用程序开发将会成为非常合适且强大的高效率开发利器.JSF 的开发环境搭建涉及到在 ...
- idea 2018 配置lombok插件及使用lombok设置实体类的getter和setter
内容简介 本文主要介绍Idea 2018中安装lombok插件,以及lombok的简单使用(生成实体类的getter和setter). lombok插件配置方法 Step 1: 打开Settings窗 ...
- [Linux实用工具]munin-node插件配置和插件编写
前面介绍了2篇munin使用的相关文章: [Linux实用工具]Linux监控工具munin的安装和配置 [Linux实用工具]Linux监控工具munin的展示(Nginx) 这次介绍一下mun ...
- 在Eclipse中配置Maven插件
--------------------------siwuxie095 在 Eclipse 中配置 Maven 插件 ...
随机推荐
- Resin任意文件读取漏洞
Resin是什么 虽然看不上但是还是原因下百度百科: Resin是CAUCHO公司的产品,是一个非常流行的支持servlets和jsp的引擎,速度非常快.Resin本身包含了一个支持HTTP/1.1的 ...
- GOOGLE和百度的长域名
GOOGLE的变态域名:www.mamashuojiusuannizhucedeyumingzaichanggoogledounengsousuochulai.cn/中文拼音:“妈妈说就算你注册的域名 ...
- BFS+优先队列+状态压缩DP+TSP
http://acm.hdu.edu.cn/showproblem.php?pid=4568 Hunter Time Limit: 2000/1000 MS (Java/Others) Memo ...
- 【模块化开发】------requireJS的基本使用------【巷子】
前言 为了提高代码的复用度,开发人员会按照功能把大量的js代码分成若干文件,这样在多个页面就可以使用同一个文件了.,下面是某个网站的js引用情况 虽然代码的复用度提升了,但是缺点也体现了出来 缺点: ...
- 关于string的length
在C++里面,std::string的length()返回的是字节数,与编码方式有关. int main() { std::string s = "我是中国人"; std::cou ...
- drop user ora-604 ora-54
SQL> drop user EFMIS_87_LK cascade;drop user EFMIS_87_LK cascade*ERROR at line 1:ORA-00604: error ...
- flask sqlaichemy中filter和filter_by
简单总结一下: 查询的三种方式: 要实现组合查询,要么连续调用filter:q = sess.query(IS).filter(IS.node == node).filter(IS.password ...
- BBS - 表、登录、文件上传、注册
一.博客系统得表关系 models.py from django.db import models from django.contrib.auth.models import AbstractUse ...
- 007-spring cache-缓存实现-02-springboot ehcahe3实现、springboot caffeine实现
一.springboot ehcahe3实现步骤 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认CacheProvider.Ehcache是一种广泛 ...
- OleDb未指定错误
桌面开发,居然也出这种问题: 1. C#读取Excel“未指定错误” http://www.connectionstrings.com/ http://www.dnetzj.com/Content/2 ...