Goal: modern Java that is immutable by default, null-safe, and testable.
Use for:
- new classes, services, or APIs in Java
- reviewing structure, immutability, and error handling
- modernizing verbose or legacy patterns
Workflow:
- Model immutable data with records and final fields.
- Use Optional for absence; avoid returning null.
- Prefer the Streams API for transformations over manual loops.
- Throw specific exceptions; never swallow them silently.
- Manage resources with try-with-resources.
- Verify with JUnit, a static analyzer, and the formatter.
Idioms:
- records for immutable value types
- Optional return types instead of null
- switch expressions and pattern matching
- var for obvious local types
- dependency injection over static singletons
Rules:
- do not return or pass null; use Optional or explicit checks
- close resources with try-with-resources, not manual finally
- keep classes focused; favor composition over inheritance
- program to interfaces for testability