language-java
Installation
SKILL.md
Java
Records and sealed types
Modern Java models data without boilerplate.
record Point(double x, double y) {}
sealed interface Shape permits Circle, Rectangle {}
record Circle(Point center, double radius) implements Shape {}
record Rectangle(Point topLeft, Point bottomRight) implements Shape {}
- Use
recordfor immutable data carriers — equals, hashCode, toString, and accessors for free. sealedcloses a hierarchy; exhaustiveswitchreplacesinstanceofchains.