赞
踩
目录
1.下载jar包(Download (projectlombok.org)),如下图所示。
2.在新建的java project中,新建一个新的文件夹lib(new -->Folder) ,如下图所示。
3.将下载好的lombok.jar复制到文件夹lib中,点lombok.jar右键Build Path-->add to Build Path。
- public class Car01 {
- //属性-数据
- public String color;
- public String brand;
- public double price;
- public int speed;
-
- //shift+alt+s --> Generate Getters and Setters产生
- public String getColor() {
- return color;
- }
- public void setColor(String color) {
- this.color = color;
- }
- public String getBrand() {
- return brand;
- }
- public void setBrand(String brand) {
- this.brand = brand;
- }
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- public int getSpeed() {
- return speed;
- }
- public void setSpeed(int speed) {
- this.speed = speed;
- }
-
- //方法
- public void run() {
- System.out.println("车正在以"+this.speed+"行驶.");
- }
-
- public int Upspeed(int s) {
- return speed -= s;
- }
-
- public int Lowspeed(int s) {
- return speed += s;
- }
- }
- import lombok.AllArgsConstructor;
- //import lombok.Data;
- import lombok.Getter;
- import lombok.NoArgsConstructor;
- import lombok.Setter;
-
- @Getter@Setter
- @NoArgsConstructor //无参构造方法
- //@Data
- @AllArgsConstructor //全参构造方法
- public class Car02 {
-
- //属性-数据
- public String color;
- public String brand;
- public double price;
- public int speed;
-
- //方法
- public void run() {
- System.out.println("车正在以"+this.speed+"行驶.");
- }
-
- public int Upspeed(int s) {
- return speed -= s;
- }
-
- public int Lowspeed(int s) {
- return speed += s;
- }
-
- }
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。