java

Solid

This skill should be used when the user works with Java files (.java), asks about "records", "sealed classes", "Optional", "streams", "composition over inheritance", or discusses modern Java patterns and API design. Provides patterns for type system usage, error handling, immutability, and concurrency.

Code & Development 17 stars 1 forks Updated yesterday MIT

Install

View on GitHub

Quality Score: 79/100

Stars 20%
42
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Java Patterns Reference for modern Java patterns, type system, and best practices. ## Iron Law > **FAVOR COMPOSITION OVER INHERITANCE** > > Delegation and interfaces over class hierarchies. Inheritance creates tight coupling, > breaks encapsulation, and makes refactoring dangerous. Use interfaces for polymorphism, > records for data, and sealed classes for restricted hierarchies. Extend only when the > "is-a" relationship is genuinely invariant. — Effective Java, Item 18 [1, Item 18] ## When This Skill Activates - Working with Java codebases (records, sealed classes, Optional, streams) - Implementing concurrent code or API design - Structuring Java packages and dependencies --- ## Type System (Modern Java) **Records for data** [4][9] — Immutable carriers with auto-generated `equals`/`hashCode`/ `toString`. Compact constructors validate before fields are sealed. ```java // BAD: Mutable POJO. GOOD: Immutable record [1, Item 17][4] public record User(String name, String email, Instant createdAt) { public User { Objects.requireNonNull(name); Objects.requireNonNull(email); } } ``` **Sealed classes** [5][9] — Close the subtype set, enabling exhaustive pattern matching. [6] ```java public sealed interface Result<T> permits Success, Failure { record Success<T>(T value) implements Result<T> {} record Failure<T>(String error) implements Result<T> {} } // Exhaustive — no default needed [6] switch (result) { case Success<User> s -> handleSuccess(s...

Details

Author
dean0x
Repository
dean0x/devflow
Created
10 months ago
Last Updated
yesterday
Language
TypeScript
License
MIT

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category