بنقرة واحدة
java21-best-practices
Modern Java 21 patterns from Virtual Threads, Pattern Matching, Records, and Sealed Classes
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Modern Java 21 patterns from Virtual Threads, Pattern Matching, Records, and Sealed Classes
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Invoke and resume YAML-defined pipelines by name — /pipeline auto-dev runs the full release pipeline
Full Self Driving — autonomous release loop that processes all auto-dev-eligible GitHub issues until none remain, by repeatedly running /pipeline auto-dev then /homework.
On explicit /homework invocation, analyze the current and linked previous sessions, extract mistakes (찐빠), and report them via omcustom-feedback with a confirmation gate. Auto-activation on session cleanup/session-end signals is OPT-IN (default OFF) — requires an explicit project/user directive. Use when explicitly auditing recent work for harness gaps.
hada.io RSS feed monitoring for AI agent/harness articles with automated /scout analysis
Pre-action boundary checking — validates agent tool calls against declared capabilities and task contracts
Auto-detect project context and optimize harness — deactivate unused agents/skills, suggest missing experts, generate project profile
استنادا إلى تصنيف SOC المهني
| name | java21-best-practices |
| description | Modern Java 21 patterns from Virtual Threads, Pattern Matching, Records, and Sealed Classes |
| scope | core |
| user-invocable | false |
Apply modern Java 21 patterns and best practices leveraging the latest language features for clean, performant, and maintainable Java code.
Embrace modern Java features over legacy patterns
Prefer immutability and data-centric design
Leverage Virtual Threads for scalable concurrency
Use Pattern Matching for expressive type handling
packages:
style: lowercase, no underscores
example: com.example.project
classes:
style: UpperCamelCase
example: OrderProcessor, UserRecord
methods_variables:
style: lowerCamelCase
example: processOrder(), itemCount
constants:
style: UPPER_SNAKE_CASE
example: static final int MAX_RETRIES = 3
records:
style: UpperCamelCase (same as class)
example: record Point(int x, int y) {}
Reference: guides/java21/java-style-guide.md
principles:
- Use Virtual Threads for I/O-bound tasks
- Avoid pooling Virtual Threads (they are lightweight)
- Replace thread pools for blocking I/O with Virtual Thread executors
patterns:
executor: "Executors.newVirtualThreadPerTaskExecutor()"
direct: "Thread.ofVirtual().start(() -> { ... })"
structured: "StructuredTaskScope.ShutdownOnFailure() for fork/join"
antipatterns:
- "Executors.newFixedThreadPool() for I/O tasks — use Virtual Threads instead"
- "Thread.sleep() on platform threads for rate limiting — use Virtual Threads"
- "synchronized blocks in Virtual Thread code — use ReentrantLock instead"
Reference: guides/java21/modern-java21.md
instanceof_patterns:
rule: "Use pattern variable binding instead of explicit casts"
guard: "Combine with && for conditional matching"
switch_patterns:
rule: "Pattern matching for switch (JEP 441) — use case Type var syntax"
guards: "Use 'when' clause for conditional cases"
null_handling: "case null supported in switch"
Reference: guides/java21/modern-java21.md
principles:
- Use Records for immutable data carriers
- Prefer Records over POJOs with getters/setters for pure data
- Compact constructors for validation
features:
validation: "Compact constructor (no parens) for input validation"
methods: "Custom methods allowed alongside auto-generated accessors"
interfaces: "Records can implement interfaces"
antipatterns:
- "Mutable state in records — records are inherently immutable"
- "Using records for entities with behavior — prefer classes"
Reference: guides/java21/modern-java21.md
patterns:
instanceof: "Deconstruct record components in instanceof check"
switch: "Deconstruct in switch case labels"
nested: "Nested record patterns for deep destructuring"
Reference: guides/java21/modern-java21.md
principles:
- Use Sealed Classes for closed type hierarchies
- Combine with Pattern Matching switch for exhaustive handling
- Prefer sealed interfaces for behavior-focused hierarchies
pattern: "sealed interface with record implementations, exhaustive switch (no default needed)"
Reference: guides/java21/modern-java21.md
principles:
- Use SequencedCollection for ordered access
- getFirst()/getLast() replace get(0) and get(size-1)
methods: "getFirst(), getLast(), addFirst(), addLast(), reversed(), firstEntry()"
Reference: guides/java21/modern-java21.md
patterns:
text_blocks: "Triple-quote \"\"\" for multi-line strings (since Java 15)"
formatted: "String.formatted() for template substitution (since Java 15)"
Reference: guides/java21/modern-java21.md
principles:
- Prefer checked exceptions for recoverable conditions
- Use unchecked exceptions for programming errors
- Never swallow exceptions silently
- Use specific exception types
patterns:
optional: "orElseThrow(() -> new SpecificException(msg)) for missing values"
multi_catch: "catch (IOException | SQLException e) for related exceptions"
Reference: guides/java21/java-style-guide.md
best_practices:
- Use @param and @return for public API
- Link related types with {@link}
- Document checked exceptions with @throws
- Keep Javadoc focused on "what", not "how"
Reference: guides/java21/java-style-guide.md
When writing or reviewing Java 21 code:
instanceof pattern matching over explicit castsgetFirst()/getLast() for sequenced collections