From swe-workbench
Java idioms — records, sealed types, virtual threads, streams, 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, records, sealed classes, or virtual threads.
How this skill is triggered — by the user, by Claude, or both
Slash command
/swe-workbench:language-javaThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Modern Java models data without boilerplate.
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 {}
record for immutable data carriers — equals, hashCode, toString, and accessors for free.sealed closes a hierarchy; exhaustive switch replaces instanceof chains.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<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."@NonNull / @Nullable for static analysis.Optional<User> find(String id) { ... }
find(id).map(User::email).orElseThrow(() -> new NotFoundException(id));
Virtual threads (Project Loom) make blocking-style IO safe at scale.
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
Future<User> user = scope.fork(() -> fetchUser(id));
Future<Order> order = scope.fork(() -> fetchOrder(orderId));
scope.join().throwIfFailed();
return new Response(user.get(), order.get());
}
Executors.newVirtualThreadPerTaskExecutor() — drop-in for newCachedThreadPool() with virtual-thread semantics.synchronized blocks and some native calls pin a virtual thread to its carrier. Prefer ReentrantLock when high-throughput blocking is expected.StructuredTaskScope (JDK 21–24 preview — not yet standard; enable with --enable-preview) enforces structured concurrency: tasks are joined before the scope exits.try-with-resources for anything AutoCloseable — never close in a finally block manually.try (var conn = dataSource.getConnection()) {
// ...
} catch (SQLException e) {
throw new RepositoryException("fetch user " + id, e);
}
Stream for transformations; avoid imperative loops when a pipeline is clearer..toList() (JDK 16+) over Collectors.toList() — returns an unmodifiable list.List.of, Map.of, Set.of for small immutable collections; Map.copyOf to defensively copy.List<String> emails = users.stream()
.filter(User::isActive)
.map(User::email)
.toList();
pom.xml with <dependencyManagement> for BOM imports; prefer the wrapper (./mvnw).build.gradle (Groovy) or build.gradle.kts (Kotlin DSL — preferred for IDE support).module-info.java): adopt only when publishing a library that needs strong encapsulation.@Test, @ParameterizedTest, @MethodSource) — not JUnit 4.assertThat(actual).isEqualTo(expected).@ParameterizedTest
@MethodSource("provideInputs")
void computesTax(double income, double expectedTax) {
assertThat(TaxCalculator.compute(income)).isCloseTo(expectedTax, within(0.01));
}
List instead of List<String>).null where Optional or a sentinel value communicates intent.static state outside of intentional singletons.equals without a matching hashCode override.CompletableFuture chain.Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.
npx claudepluginhub lugassawan/swe-workbench --plugin swe-workbench