以上のことしかしないクラス 用途の例: (複数の値の)戻り値, (複数の値の)パラメーター, 範囲などのルールがあるデータ, Data Transfer Object, ... Data Class / Data Career Class とは? 6 public class Point { private final int x; private final int y; public Point(int x, int y) { this.x = x; this.y = y; } public int x() { return x; } public int y() { return y; } @Override public String toString() { /* x,y Λදࣔ */ } @Override public boolean equals(Object o) { /* o ͷ x,y ͱൺֱ */ } @Override public int hashCode() { /* x,yͷϋογϡΛੜ */ } } どんなクラス? 例えば...
Point { private final int x; private final int y; public Point(int x, int y) { this.x = x; this.y = y; } public int x() { return x; } public int y() { return y; } @Override public String toString() { /* x,y Λදࣔ */ } @Override public boolean equals(Object o) { /* o ͷ x,y ͱൺֱ */ } @Override public int hashCode() { /* x,yͷϋογϡΛੜ */ } } ⇒ record Point (int x, int y) {};
https://www.infoq.com/jp/news/2018/03/data-classes-for-java/ • Data Classes and Sealed Types for Java https://cr.openjdk.java.net/~briangoetz/amber/datum.html • 参考資料 11