← ClaudeAtlas

language-javalisted

Java idioms — records, sealed types, virtual threads, and JDK 21+ patterns. Auto-load when working with .java files, pom.xml, build.gradle, or when the user mentions Java, JVM, Spring, Maven, Gradle, sealed classes, or virtual threads.
lugassawan/swe-workbench · ★ 2 · Web & Frontend · score 68
Install: claude install-skill lugassawan/swe-workbench
# Java ## Records and sealed types Modern Java models data without boilerplate. ```java 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 `record` for immutable data carriers — equals, hashCode, toString, and accessors for free. - `sealed` closes a hierarchy; exhaustive `switch` replaces `instanceof` chains. ```java double area = switch (shape) { case Circle c -> Math.PI * c.radius() * c.radius(); case Rectangle r -> Math.abs(r.bottomRight().x() - r.topLeft().x()) * Math.abs(r.bottomRight().y() - r.topLeft().y()); }; ``` ## Optional and null discipline - Return `Optional<T>` from methods that may have no result; never use it as a field or parameter type. - `Optional` is not a null check replacement — it signals "absence is a valid outcome." - Annotate parameters and fields with `@NonNull` / `@Nullable` for static analysis. - Jackson populates `List<T>` with literal nulls from valid JSON (`{"content":[null]}`) regardless of declared nullability — filter before mapping over an externally-deserialized collection, or drop them at the boundary with `@JsonSetter(contentNulls = Nulls.SKIP)`. ```java Optional<User> find(String id) { ... } find(id).map(User::email).orElseThrow(() -> new NotFoundException(id)); List<String> ids = payload.content().stream()