Data-Classes

1 post in this section

Records (JEP 395): Immutable Data Classes Without the Boilerplate

Finalized in Java 16 (JEP 395). Available in all Java 16+ releases, including Java 17. Previous previews: Java 14 (JEP 359) and Java 15 (JEP 384). The Problem: Data Classes in Java Writing a simple immutable data class in Java 11 requires significant boilerplate: public final 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 boolean equals(Object o) { if (this == o) return true; if (!

Continue reading »