public class BirthDay {
private int day;
private int month;
private int year;
}
다음과 같은 private 접근 제어자로 선언된 변수들이 있을 때 우리는 해당 변수들을 이용할 수 있도록 getter, setter 메서드를 만들어줘야 한다. 그런데 IntelliJ에서는 단축키로 메서드를 한번에 생성하기 편리한 기능을 만들어 놓았다.
해당 단축키를 눌러보면
다음과 같은 그림이 생성되는데 필요한 것을 선택하여 생성하면 된다.
public class BirthDay {
private int day;
private int month;
private int year;
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
}
Alt+Insert 키를 꼭 기억해두도록 하자!