1.首先创建好一个类,里面可以暂时有2个属性。
public class Student {
private int id;
private String name;
private int age;
private String hobby;
}
2.鼠标在编辑区右击,弹出对话框,点击generate
,或者点击Code中的generate,
或者是使用快捷键Alt + Insert
。
3. 选择自动生成构造器
或者是set()
和get()
方法点击即可。
4.选中需要生成的方法 ,然后点击OK。
下面是生成后的结果
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
5.生成给类赋值的语句
下面为结果
public Student(int id, String name, int age, String hobby) {
this.id = id;
this.name = name;
this.age = age;
this.hobby = hobby;
}