LomBok 的相关目录已经整理出来,希望大家可以根据需求自助学习,好工具要大家分享:
- 浏览: 227634 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
w574240966:
旭哥 涨姿势了。。。
Lombok 之 Cleanup -
cuisuqiang:
不错,自定义对象对比方法的实现
Lombok 之 EqualsAndHashCode -
sundoctor:
jdk 7
import lombok.Cleanup ...
Lombok 之 Cleanup -
朱秋旭:
kjj 写道java7 已经不需要这个了 try就可以这个只是 ...
Lombok 之 Cleanup -
kjj:
java7 已经不需要这个了 try就可以
Lombok 之 Cleanup
先说@Data , 作为之前介绍几个annotation的一个统称,可谓整理了方便,@Data直接修饰POJO or beans, getter所有的变量,setter所有不为final的变量。如果你不需要默认的生成方式,直接填写你需要的annotation的就可以了。默认生成的所有的annotation都是public的,如果需要不同权限修饰符可以使用AccessLevel.NONE选项。当然@Data 也可以使用staticConstructor选项生成一个静态方法。
使用Data annotation可以简便的完成自己想要的内容:
import lombok.AccessLevel;
import lombok.Setter;
import lombok.Data;
import lombok.ToString;
@Data public class DataExample {
private final String name;
@Setter(AccessLevel.PACKAGE) private int age;
private double score;
private String[] tags;
@ToString(includeFieldNames=true)
@Data(staticConstructor="of")
public static class Exercise<T> {
private final String name;
private final T value;
}
}
使用后:
import java.util.Arrays;
public class DataExample {
private final String name;
private int age;
private double score;
private String[] tags;
public DataExample(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
void setAge(int age) {
this.age = age;
}
public int getAge() {
return this.age;
}
public void setScore(double score) {
this.score = score;
}
public double getScore() {
return this.score;
}
public String[] getTags() {
return this.tags;
}
public void setTags(String[] tags) {
this.tags = tags;
}
@Override public String toString() {
return "DataExample(" + this.getName() + ", " + this.getAge() + ", " + this.getScore() + ", " + Arrays.deepToString(this.getTags()) + ")";
}
protected boolean canEqual(Object other) {
return other instanceof DataExample;
}
@Override public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof DataExample)) return false;
DataExample other = (DataExample) o;
if (!other.canEqual((Object)this)) return false;
if (this.getName() == null ? other.getName() != null : !this.getName().equals(other.getName())) return false;
if (this.getAge() != other.getAge()) return false;
if (Double.compare(this.getScore(), other.getScore()) != 0) return false;
if (!Arrays.deepEquals(this.getTags(), other.getTags())) return false;
return true;
}
@Override public int hashCode() {
final int PRIME = 59;
int result = 1;
final long temp1 = Double.doubleToLongBits(this.getScore());
result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode());
result = (result*PRIME) + this.getAge();
result = (result*PRIME) + (int)(temp1 ^ (temp1 >>> 32));
result = (result*PRIME) + Arrays.deepHashCode(this.getTags());
return result;
}
public static class Exercise<T> {
private final String name;
private final T value;
private Exercise(String name, T value) {
this.name = name;
this.value = value;
}
public static <T> Exercise<T> of(String name, T value) {
return new Exercise<T>(name, value);
}
public String getName() {
return this.name;
}
public T getValue() {
return this.value;
}
@Override public String toString() {
return "Exercise(name=" + this.getName() + ", value=" + this.getValue() + ")";
}
protected boolean canEqual(Object other) {
return other instanceof Exercise;
}
@Override public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof Exercise)) return false;
Exercise<?> other = (Exercise<?>) o;
if (!other.canEqual((Object)this)) return false;
if (this.getName() == null ? other.getValue() != null : !this.getName().equals(other.getName())) return false;
if (this.getValue() == null ? other.getValue() != null : !this.getValue().equals(other.getValue())) return false;
return true;
}
@Override public int hashCode() {
final int PRIME = 59;
int result = 1;
result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode());
result = (result*PRIME) + (this.getValue() == null ? 0 : this.getValue().hashCode());
return result;
}
}
}
与@Data相对应的@Value, 两个annotation的主要区别就是如果变量不加@NonFinal ,@Value会给所有的弄成final的。当然如果是final的话,就没有set方法了。
import lombok.AccessLevel; import lombok.experimental.NonFinal; import lombok.experimental.Value; import lombok.experimental.Wither; import lombok.ToString; @Value public class ValueExample { String name; @Wither(AccessLevel.PACKAGE) @NonFinal int age; double score; protected String[] tags; @ToString(includeFieldNames=true) @Value(staticConstructor="of") public static class Exercise<T> { String name; T value; } }
使用后:
import java.util.Arrays;
public final class ValueExample {
private final String name;
private int age;
private final double score;
protected final String[] tags;
@java.beans.ConstructorProperties({"name", "age", "score", "tags"})
public ValueExample(String name, int age, double score, String[] tags) {
this.name = name;
this.age = age;
this.score = score;
this.tags = tags;
}
public String getName() {
return this.name;
}
public int getAge() {
return this.age;
}
public double getScore() {
return this.score;
}
public String[] getTags() {
return this.tags;
}
@java.lang.Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof ValueExample)) return false;
final ValueExample other = (ValueExample)o;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
if (this.getAge() != other.getAge()) return false;
if (Double.compare(this.getScore(), other.getScore()) != 0) return false;
if (!Arrays.deepEquals(this.getTags(), other.getTags())) return false;
return true;
}
@java.lang.Override
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 0 : $name.hashCode());
result = result * PRIME + this.getAge();
final long $score = Double.doubleToLongBits(this.getScore());
result = result * PRIME + (int)($score >>> 32 ^ $score);
result = result * PRIME + Arrays.deepHashCode(this.getTags());
return result;
}
@java.lang.Override
public String toString() {
return "ValueExample(name=" + getName() + ", age=" + getAge() + ", score=" + getScore() + ", tags=" + Arrays.deepToString(getTags()) + ")";
}
ValueExample withAge(int age) {
return this.age == age ? this : new ValueExample(name, age, score, tags);
}
public static final class Exercise<T> {
private final String name;
private final T value;
private Exercise(String name, T value) {
this.name = name;
this.value = value;
}
public static <T> Exercise<T> of(String name, T value) {
return new Exercise<T>(name, value);
}
public String getName() {
return this.name;
}
public T getValue() {
return this.value;
}
@java.lang.Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof ValueExample.Exercise)) return false;
final Exercise<?> other = (Exercise<?>)o;
final Object this$name = this.getName();
final Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
final Object this$value = this.getValue();
final Object other$value = other.getValue();
if (this$value == null ? other$value != null : !this$value.equals(other$value)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $name = this.getName();
result = result * PRIME + ($name == null ? 0 : $name.hashCode());
final Object $value = this.getValue();
result = result * PRIME + ($value == null ? 0 : $value.hashCode());
return result;
}
@java.lang.Override
public String toString() {
return "ValueExample.Exercise(name=" + getName() + ", value=" + getValue() + ")";
}
}
}
发表评论
-
Lombok 之 Log
2014-10-03 15:12 11858LomBok 的相关目录已经整理出来,希望大家可以根据需求 ... -
Lombok 之 @Getter(lazy=true)
2014-10-03 15:03 4118LomBok 的相关目录已经整理出来,希望大家可以根据需求 ... -
Lombok 之 Synchronized
2014-10-03 14:35 4118LomBok 的相关目录已经整理出来,希望大家可以根据需求 ... -
Lombok 之 SneakyThrows
2014-10-03 15:17 9903LomBok 的相关目录已经整理出来,希望大家可以根据需求 ... -
Lombok 之 Constructor
2014-10-02 17:51 20454LomBok 的相关目录已经 ... -
Lombok 之 EqualsAndHashCode
2014-10-02 12:19 13257LomBok 的相关目录已经整理出来,希望大家可以根据需求 ... -
Lombok 之 ToString
2014-10-02 11:43 30079LomBok 的相关目录已经整理出来,希望大家可以根据需求 ... -
Lombok 之 Getter&Setter
2014-10-02 00:49 7048LomBok 的相关目录已经整理出来,希望大家可以根据需求 ... -
Lombok 之 Cleanup
2014-10-01 22:07 5072LomBok 的相关目录已经整理出来,希望大家可以根据需求 ... -
被Java世界忽视的Lombok
2014-10-01 21:00 6395在祖国65岁生日之际,道一声生日快乐,也祝大家国庆节hap ...
相关推荐
解压后使用:lombok.jar
主要给大家介绍了关于java中lombok的@Data引发问题的相关资料,文中通过图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
由于项目中有@Slf4j 注解等,而eclipse需要安装lombok插件才能正常编译。总结了一下【windows环境】和【ubuntu环境】
lombok.jar lombok.jar lombok.jar lombok.jar 亲测好用!!!
试一试
lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 lombok 1.18.24 ...
lombok(1.16.18版本)最新包, 1、下载Lombok.jar 2、双击运行Lombok.jar 数秒后将弹出一框,以确认eclipse的安装路径 3、确认完eclipse的安装路径后,点击install/update按钮,即可安装完成 4、安装完成之后,请...
lombok
lombok_lombok.zip
lombok_lombok_源码.zip
lombok.jar在eclipse和sts中做相应配置可以代替get、set
lombok 1.18.24
eclipse安装lombok支持的jar包,一键安装,简单轻松可用
Lombok安装及使用,里面包含文档说明及jar包,安装步骤、例子都在里面,欢迎使用
赠送jar包:lombok-1.16.10.jar; 赠送原API文档:lombok-1.16.10-javadoc.jar; 赠送源代码:lombok-1.16.10-sources.jar; 赠送Maven依赖信息文件:lombok-1.16.10.pom; 包含翻译后的API文档:lombok-1.16.10-...
IDEA lombok 插件 get set方法可以提示
下载Lombok,版本为Lombok1.18.6.jar(因jdk1.8与1.16.x版本不匹配,所以才升级1.18.x版本) 安装方法: 将Lombok1.18.6.jar复制到eclipse安装目录下之后鼠标双击它,然后点击弹窗页面的Specify location按钮之后...
赠送jar包:lombok-1.16.20.jar; 赠送原API文档:lombok-1.16.20-javadoc.jar; 赠送源代码:lombok-1.16.20-sources.jar; 赠送Maven依赖信息文件:lombok-1.16.20.pom; 包含翻译后的API文档:lombok-1.16.20-...
将lombok.jar文件,放到eclipse安装路径,该jar包也就是lombok插件的jar文件了 打开eclipse.ini文件,添加如下内容: -javaagent:lombok.jar -Xbootclasspath/a:lombok.jar 重启eclipse
IDEA lombok 插件 lombok-plugin-0.8.8-14