Sco*_*ion 10 java eclipse lombok
我正在尝试使用lombok getter和setter注释.据我所知,带注释的代码是在运行时生成的而不是编译时间,那么如何利用自动生成的getter和setter来编写代码呢?
例如,我有一个这样的类
@lombok.Getters
@lombok.Setters
public class MyLombokTesting {
private String userName;
}
Run Code Online (Sandbox Code Playgroud)
但是如果在编写代码时没有生成这些注释会有什么用?
现在我想做这样的事情
MyLombokTesting myLombokTesting = new MyLombokTesting();
String username = myLombokTesting.getUserName();
or myLombokTesting.setUserName("some username");
Run Code Online (Sandbox Code Playgroud)
但我不能做任何这些,因为在编写代码时没有为eclipse生成的setter和getter.
显然我可以有一个参数构造函数来设置用户名但是getter呢?
Roe*_*ker 12
First of all, Lombok does run compile time to change the generated class file on the fly.
Possibly, lombok is not correctly installed in your Eclipse. See this answer on lombok installation problems in Eclipse.
Furthermore, the runtime processing of annotations is not the only use for them. Java 5 already shipped with apt, the Annotation Processing Tool and since java 6 annotations can be processed by the standard compiler (javac). Annotations can generate class files, source files or other resource files.
Disclosure: I am one of the Project Lombok developers
归档时间: |
|
查看次数: |
20462 次 |
最近记录: |