Lombok

Lombok Requires Annotation Processing

别来无恙 提交于 2019-11-27 17:06:24
问题 I'm using Android Studio 2.2 Preview 7, and the Lombok plugin suddenly started saying: Annotation processing seems to be disabled for the project X , and providing a link to settings. Clicking on the notification does not take me to the right place. What is the fix for this? 回答1: The Settings opened by clicking the notification are the Per Project settings, and those are not what you need in this case. To fix this, go to File->Other Settings->Default Settings Expand Build, Execution,

Build an object from an existing one using lombok

五迷三道 提交于 2019-11-27 14:33:49
Lets say I have a lombok annotated class like @Builder class Band { String name; String type; } I know I can do: Band rollingStones = Band.builder().name("Rolling Stones").type("Rock Band").build(); Is there an easy way to create an object of Foo using the existing object as a template and changing one of it's properties? Something like: Band nirvana = Band.builder(rollingStones).name("Nirvana"); I can't find this in the lombok documentation. Roel Spilker You can use the toBuilder parameter to give your instances a toBuilder() method. @Builder(toBuilder=true) class Foo { int x; ... } Foo f0 =

how to configure lombok in eclipse luna

人盡茶涼 提交于 2019-11-27 14:16:08
I configure lombok in eclipse Luna with Maven. Annotation is added properly, but no getter and setter are generated. eclipse.ini `-vm E:\Program Files\Java\jdk1.7.0_60\bin` `-vmargs` `-Dosgi.requiredJavaVersion=1.7` `-javaagent:F:\Tools\Java Lib\Lombok\lombok.jar` `-Xbootclasspath/a:F:\Tools\Java Lib\Lombok\lombok.jar` `-Xms40m` `-Xmx512m` Roel Spilker Disclosure: I am one of the lombok developers. I might be biased :-) I strongly suggest installing Lombok via executing the lombok jar: java -jar lombok.jar The spaces in the path might be a problem. Also, you'll need to use lombok version 1.14

lombok 简化java代码注解 理解

[亡魂溺海] 提交于 2019-11-27 13:17:46
lombok 注解: lombok 提供的注解不多,可以参考官方视频的讲解和官方文档。 Lombok 注解在线帮助文档: http://projectlombok.org/features/index. 下面介绍几个我常用的 lombok 注解: @Data :注解在类上;提供类所有属性的 getting 和 setting 方法,此外还提供了equals、canEqual、hashCode、toString 方法 @Setter :注解在属性上;为属性提供 setting 方法 @Getter :注解在属性上;为属性提供 getting 方法 @Log4j :注解在类上;为类提供一个 属性名为log 的 log4j 日志对象 @NoArgsConstructor :注解在类上;为类提供一个无参的构造方法 @AllArgsConstructor :注解在类上;为类提供一个全参的构造方法 下面是简单示例 1.不使用 lombok 的方案 1 2public class Person { 3 4 private String id; 5 private String name; 6 private String identity; 7 private Logger log = Logger.getLogger(Person.class); 8 9 public Person() {

lombok的使用和原理

拥有回忆 提交于 2019-11-27 13:17:19
一、项目背景 在写Java程序的时候经常会遇到如下情形: 新建了一个Class类,然后在其中设置了几个字段,最后还需要花费很多时间来建立getter和setter方法 lombok项目的产生就是为了省去我们手动创建getter和setter方法的麻烦,它能够在我们编译源码的时候自动帮我们生成getter和setter方法。即它最终能够达到的效果是:在源码中没有getter和setter方法,但是在编译生成的字节码文件中有getter和setter方法 比如源码文件: import java.io.Serializable; import lombok.Data; @Data public class BasicClusterInfo implements Serializable { private static final long serialVersionUID = 3478135817352393604L; private String hbaseKey; private int receiverCount; } 以下是编译上述源码文件得到的字节码文件,对其反编译得到的结果 public class BasicClusterInfo extends java.lang.Object implements java.io.Serializable{ public

FindBugs引出的Lombok @Data注解使用的问题

我怕爱的太早我们不能终老 提交于 2019-11-27 13:17:06
今天用FindBugs查看代码质量的时候看到如下的提示 @Data注解包含了getter settter equals hashCode方法 上面的英文是:重写equals方法可能会导致equals方法失去它的一致性原则,这个问题会出现a.equals(b)==true,b.equals(a)==false的情况。 补充: 重写equals方法的要点: 1 自反性:对于任意的引用值x,x.equals(x)一定为true 2 对称性:对于任意的引用值x 和 y,当x.equals(y)返回true,y.equals(x)也一定返回true 3 传递性:对于任意的引用值x、y和z,如果x.equals(y)返回true,并且y.equals(z)也返回true,那么x.equals(z)也一定返 回 true 4 一致性:对于任意的引用值x 和 y,如果用于equals比较的对象信息没有被修改, 多次调用x.equals(y)要么一致地返回true,要么一致地返回false 5 非空性:对于任意的非空引用值x,x.equals(null)一定返回false 请注意:重写equals方法后最好重写hashCode方法,否则两个等价对象可能得到不同的hashCode,这在集合框架中使用可能产生严重后果 下面关于使用Lombok的可能踩坑详细描述是转载的 http://www

Kotlin doesn't see Java Lombok accessors?

喜欢而已 提交于 2019-11-27 12:33:10
Using Kotlin 1.0.0 release (compiling in IntelliJ 15). println(myPojoInstance.foo) When it tries to compile code (in IntelliJ or Gradle) that references Lombok based POJOs it gives the error "Cannot access 'foo': it is 'private' in "MyPojo". Which is true, they're all private and my object has @Value @Builder for lombok annotations. I've tried specifically calling getFoo(), but it says "unresolved reference for getFoo". There's perhaps some trick to make Kotlin aware of how to handle the lombok annotations? Generally, no, it doesn't. The reason of that behavior is that Lombok is an annotation

How to ignore the Java Source directory during Maven Compilation?

眉间皱痕 提交于 2019-11-27 12:17:17
问题 I am trying to use the Lombok Maven Plugin to ensure the correct creation of Javadocs when using Lombok. Lombok Maven introduces a new code generation goal, just prior to compilation. In my configuration, my sourceDirectory (Java with Lombok annotations, src/main/java ) is processed to create Java (without Lombok annotations) in target/generated-sources/delombok . However, every file in sourceDirectory now has a corresponding (identically named) file in target/generated-sources/delombok ,

Writing custom Lombok Annotation handlers

旧街凉风 提交于 2019-11-27 12:05:46
问题 I want to write custom Lombok Annotation handlers. I know http://notatube.blogspot.de/2010/12/project-lombok-creating-custom.html. But the current lombok jar file does not contain many .class files, but files named .SCL.lombok instead. I found, the .SCL.lombok files are the .class files, the build script of Lombok does rename them while generating the jar file, and the ShadowClassLoader is capable of loading these classes -- and the acronym SCL seems to come from this. It seems the reason for

Lombok how to customise getter for Boolean object field?

↘锁芯ラ 提交于 2019-11-27 10:45:12
问题 One of my POJOs has a Boolean object field to permit NULLS in the database (a requirement). Is it possible to use the @Data Lombok annotation at class level yet override the getter for the Boolean field? The default it generates is getXXX method for the Boolean field. I wish to override it as isXXX()? Thanks, Paddy 回答1: It's a bit verbose, but you can provide your own isXXX , and then use AccessLevel.NONE to tell Lombok not to generate the getXXX : @Data public class OneOfPaddysPojos { // ...