Skip to content

Java 21 patterns for records, sealed hierarchies, and virtual threads that keep code immutable and safe.

CCM score
57 of 100
skills.sh installs
334
GitHub stars
681
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers three core patterns: immutable records with compact-constructor validation, sealed types with exhaustive switch matching, and virtual threads for blocking I/O
  • Includes worked examples for a validated Email record, a sealed Payment hierarchy, and a virtual-thread-per-task fetcher
  • Flags anti-patterns to avoid, such as mutable public-field DTOs and raw platform threads created per request
  • Designed for Java 21 application and library code that models DTOs, closed hierarchies, or blocking I/O

Install

$ npx -y skills add gentleman-programming/gentleman-skills --skill java-21 -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

When to Use

Load this skill when:

  • Writing Java 21 application or library code
  • Designing immutable DTOs or value objects
  • Modeling closed hierarchies with sealed types
  • Using virtual threads for blocking I/O

Critical Patterns

Pattern 1: Records for immutable data

Use records for DTOs and value objects, validate in compact constructors.

Pattern 2: Sealed types + pattern matching

Use sealed interfaces/classes and switch pattern matching for exhaustiveness.

Pattern 3: Virtual threads for I/O

Use virtual threads to handle blocking I/O without large thread pools.

Code Examples

Example 1: Record with validation

package com.acme.user;

public record Email(String value) {
  public Email {
    if (value == null || !value.contains("@")) {
      throw new IllegalArgumentException("Invalid email");
    }
  }
}

Example 2: Sealed hierarchy + switch pattern matching

package com.acme.payment;

public sealed interface Payment permits Card, BankTransfer { }

public record Card(String last4) implements Payment { }
public record BankTransfer(String iban) implements Payment { }

Details

Repository
github.com/gentleman-programming/gentleman-skills
Category
Java & JVM
First seen
Jun 3, 2026

Questions

What does the java-21 skill do?

The java-21 skill teaches an agent Java 21 language and runtime patterns for modern, safe code. It covers records for immutable data with validation in compact constructors, sealed types with switch pattern matching, and virtual threads for blocking I/O.

How do I install the java-21 skill?

Run npx -y skills add gentleman-programming/gentleman-skills --skill java-21 -y inside a project to install the java-21 skill. Once installed, the agent can write Java 21 application and library code using records, sealed types and virtual threads.

Which category does java-21 belong to, and what sets it apart?

The java-21 skill is in the Java and JVM category on Claude Marketplaces and ranks in the top 100 there. It is narrower than the other skills in that category because it focuses only on Java 21 features such as records, sealed hierarchies and virtual threads.

Who is java-21 for?

The java-21 skill is for developers writing Java 21 code who want immutable DTOs and value objects, closed hierarchies modeled with sealed types, or scalable blocking I/O with virtual threads. It also warns against mutable data carriers and raw platform threads per request.

More from gentleman-programming/gentleman-skills

All 13

Similar to Java 21

More Java & JVM