1、创建类:GetterSetter,这是一个没有使用lombok的类
package im.ubu.java.lombok;
/**
* @Author hiwon(116268012 @ qq.com)
* @Description TODO
**/
public class GetterSetter {
private String name = "ubu";
private int height = 170;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}
2、创建类:GetterSetter,这是一个使用lombok的类
package im.ubu.java.lombok;
import lombok.Getter;
import lombok.Setter;
/**
* @Author hiwon(116268012 @ qq.com)
* @Description TODO
**/
public class GetterSetterLombok {
@Getter @Setter private String name;
@Getter @Setter private int height;
}
3、创建类:测试类 GetterSetterTest,执行
package im.ubu.java.lombok;
import org.apache.log4j.Logger;
/**
* @Author hiwon(116268012 @ qq.com)
* @Description TODO
**/
public class GetterSetterTest {
private static final Logger LOG = Logger.getLogger(GetterSetterTest.class);
public static void main(String[] args) {
//没有使用lombok
GetterSetterTest.GetterSetterMethod();
//使用lombok
GetterSetterTest.GetterSetterLombokMethod();
}
public static void GetterSetterMethod(){
GetterSetter gsd = new GetterSetter();
gsd.setHeight(180);
gsd.setName("ubu");
LOG.info(gsd.getName() + " & " + gsd.getHeight());
}
public static void GetterSetterLombokMethod(){
GetterSetterLombok gsd = new GetterSetterLombok();
gsd.setName("ubu_lombok");
gsd.setHeight(190);
LOG.info( gsd.getName() + " & " + gsd.getHeight());
}
}
4、查看结果,使用lombok的效果是一样的