在我的项目中,我使用 Command + N 来生成setter和getter方法。
我的代码如下:
public class Employee {
private int empId;
private String empName;
private Date workDate;
}
但最终,setter和getter方法处于不利的顺序:它变为:
public class Employee {
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public Date getWorkDate() {
return workDate;
}
public void setWorkDate(Date workDate) {
this.workDate = workDate;
}
private int empId;
private String empName;
private Date workDate;
}
但我想在属性下使用getter和setter方法。
public class Employee {
private int empId;
private String empName;
private Date workDate;
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public Date getWorkDate() {
return workDate;
}
public void setWorkDate(Date workDate) {
this.workDate = workDate;
}
}
怎么办呢?
答案 0 :(得分:0)
生成getter和setter时,光标位置应该是属性的结尾。
像这样: