레코드 클래스는 확장 가능한 동작보다는 불변 데이터를 모델링하는 데 주안점을 둡니다.
equals() 및 접근자와 같이 데이터 기반 메서드의 묵시적 자동 구현은 상용구 코드를 줄이는 데 유용합니다.
단, 모든 클래스가 레코드 클래스가 될 수 있는 것은 아닙니다. 다음 몇 가지 제한 사항입니다:
레코드 클래스에 대한 자세한 설명은 Java 언어 사양을 참조하세요.
예:
class Point {
private final double x;
private final double y;
Point(double x, double y) {
this.x = x;
this.y = y;
}
double getX() {
return x;
}
double getY() {
return y;
}
}
빠른 수정을 적용한 후:
record Point(int x, int y) {
}
getX()/isX() 접근자 이름을 x()로 자동 변경하려면, 접근자 이름 변경 제안 옵션을 활성화하세요.
Use the Disable highlighting if members become more accessible option to exclude classes whose members' accessibility would be weakened by conversion. Quick-fix will stay available as an intention, and triggering it will show the affected members and ask for confirmation. 배치 모드에서는 변환이 제안되지 않습니다.
지정된 패턴과 일치하는 어노테이션이 추가된 경우, 변환에서 클래스를 제외하려면 Suppress conversion if class is annotated by(클래스에 다음 어노테이션이 추가된 경우 변환 억제) 목록을 사용하세요.
2020.3의 새로운 기능