141-java-refactoring-with-modern-features — Claude Code skill: modern
A skill that moves legacy Java code onto modern language features: lambdas, Stream API, Optional, java.time. Useful when a codebase needs cleanup.
npx skills add jabrena/plinth --skill 141-java-refactoring-with-modern-features -a claude-codeWhat 141-java-refactoring-with-modern-features does
The skill looks for spots where Java code can be rewritten with Java 8+ features and newer. The list covers lambdas and method references instead of anonymous classes, Stream API instead of Iterator loops, Optional for null-safe APIs, java.time instead of Date and Calendar, collection factory methods (List.of(), Set.of(), Map.of()), text blocks, and var type inference. Java 25 features get their own section: flexible constructor bodies (JEP 513) and module import declarations (JEP 511).
It runs as a sequence of steps. First the skill requires a build with ./mvnw compile or mvn compile and stops if that fails. Then it reads references/141-java-refactoring-with-modern-features.md, which holds good and bad code examples for each area, and picks candidates. Refactoring happens incrementally, behavior preserved, and the run ends with ./mvnw clean verify or mvn clean verify.
Compiling first is not a formality. If the project does not build, the skill halts and leaves the code alone, because otherwise you cannot tell an old error from a new one. When the scope of a request is unclear it asks a clarifying question, and when files or tooling are missing it reports what is absent.
What it helps with
- rewrite anonymous classes as lambdas and method references
- replace
Iteratorloops with Stream API calls - drop null checks in favor of
Optional - move date handling from
DateandCalendartojava.time - build immutable collections with
List.of()andMap.of()
Example prompts for the agent
- go through the service layer and replace anonymous classes with lambdas
- rewrite this
Iteratorloop using the Stream API - swap
Dateforjava.timein this class
How to install 141-java-refactoring-with-modern-features
1Skills CLI (Vercel)
npx skills add jabrena/plinth --skill 141-java-refactoring-with-modern-features -a claude-code2Manually: put the files in place
~/.claude/skills/141-java-refactoring-with-modern-features/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/141-java-refactoring-with-modern-features/
1Skills CLI (Vercel)
npx skills add jabrena/plinth --skill 141-java-refactoring-with-modern-features -a codex2Manually: put the files in place
.agents/skills/141-java-refactoring-with-modern-features/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add jabrena/plinth --skill 141-java-refactoring-with-modern-features -a cursor2Manually: put the files in place
.cursor/skills/141-java-refactoring-with-modern-features/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install jabrena/plinth 141-java-refactoring-with-modern-features2Manually: put the files in place
.github/skills/141-java-refactoring-with-modern-features/SKILL.md1Skills CLI (Vercel)
npx skills add jabrena/plinth --skill 141-java-refactoring-with-modern-features -a gemini-cli2Platform CLI
gemini skills install https://github.com/jabrena/plinth --path skills/141-java-refactoring-with-modern-featuresManually: put the files in place
.devin/skills/141-java-refactoring-with-modern-features/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add jabrena/plinth --skill 141-java-refactoring-with-modern-features -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about 141-java-refactoring-with-modern-features
How do I install 141-java-refactoring-with-modern-features in Claude?
Run npx skills add jabrena/plinth --skill 141-java-refactoring-with-modern-features -a claude-code. The skill file lands at ~/.claude/skills/141-java-refactoring-with-modern-features/SKILL.md.
What does 141-java-refactoring-with-modern-features do?
It finds Java code that can move to Java 8+ and Java 25 features and applies the changes step by step. It compiles the project first and runs a full verification afterwards.
What does the skill need to work?
The project has to compile before anything else: the skill runs ./mvnw compile or mvn compile and stops on a build failure. If the scope is unclear, it asks a clarifying question first.
Source text
SKILL.md · Apache-2.0
--- name: 141-java-refactoring-with-modern-features description: Use when you need to refactor Java code to adopt modern Java features (Java 8+) — including migrating anonymous classes to lambdas, replacing Iterator loops with Stream API, adopting Optional for null safety, switching from legacy Date/Calendar to java.time, using collection factory methods, applying text blocks, var inference, or leveraging Java 25 features like flexible constructor bodies and module import declarations. This should trigger for requests such as Review Java code for modern Java development; Apply best practices for modern Java development in Java code; Modernize Java code with records pattern matching or switch expressions; Replace legacy idioms with modern Java features; Adopt Java 8+ language features safely. Part of Plinth Toolkit license: Apache-2.0 metadata: author: Juan Antonio Breña Moral version: 0.19.0 --- # Modern Java Development Guidelines (Java 8+) Identify and apply modern Java (Java 8+) refactoring opportunities to improve readability, maintainability, and performance. **What is covered in this Skill?** - Lambda expressions and method references (over anonymous classes) - Stream API for declarative collection processing - `Optional` for null-safe APIs - `java.time` API (replacing `Date`/`Calendar`) - Default interface methods, `var` type inference - Unmodifiable collection factory methods (`List.of()`, `Set.of()`, `Map.of()`) - Text blocks for multi-line strings - Java 25 Flexible Constructor Bodies (JEP 513) - Java 25 Module Import Declarations (JEP 511) **Scope:** The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples. ## Constraints Before applying any modern Java refactoring, ensure the project compiles. If compilation fails, stop immediately — do not proceed until the project compiles successfully. After applying improvements, run full verification. - **MANDATORY**: Run `./mvnw compile` or `mvn compile` before applying any changes - **SAFETY**: If compilation fails, stop immediately — do not proceed until the project compiles successfully - **VERIFY**: Run `./mvnw clean verify` or `mvn clean verify` after applying improvements - **BEFORE APPLYING**: Read the reference for detailed good/bad examples, constraints, and safeguards for each modern Java feature - **EDGE CASE**: If request scope is ambiguous, stop and ask a clarifying question before applying changes - **EDGE CASE**: If required inputs, files, or tooling are missing, report what is missing and ask whether to proceed with setup guidance ## When to use this skill - Review Java code for modern Java development - Apply best practices for modern Java development in Java code - Modernize Java code with records pattern matching or switch expressions - Replace legacy idioms with modern Java features - Adopt Java 8+ language features safely ## Workflow 1. **Compile project before modernization** Run `./mvnw compile` or `mvn compile` and stop immediately if compilation fails. 2. **Read modern-Java reference and identify candidates** Read `references/141-java-refactoring-with-modern-features.md` and identify high-value opportunities to adopt modern Java features. 3. **Apply modern Java refactorings** Refactor incrementally using appropriate language/library features while preserving behavior and readability. 4. **Verify with full build** Run `./mvnw clean verify` or `mvn clean verify` after applying improvements. ## Reference For detailed guidance, examples, and constraints, see [references/141-java-refactoring-with-modern-features.md](references/141-java-refactoring-with-modern-features.md).
© Juan Antonio Breña Moral · Apache-2.0 · jabrena/plinth