Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add jabrena/plinth --skill 141-java-refactoring-with-modern-features -a claude-code
Open on GitHub

What 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 Iterator loops with Stream API calls
  • drop null checks in favor of Optional
  • move date handling from Date and Calendar to java.time
  • build immutable collections with List.of() and Map.of()

Example prompts for the agent

  • go through the service layer and replace anonymous classes with lambdas
  • rewrite this Iterator loop using the Stream API
  • swap Date for java.time in 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-code

2Manually: put the files in place

~/.claude/skills/141-java-refactoring-with-modern-features/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/141-java-refactoring-with-modern-features/

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

Similar skills

All skills for Code review and refactoring →

From the same set51

110-java-maven-best-practices Reviews and rewrites Maven configuration against industry practices: BOM-based dependency management, centralized versions, multi-module builds. CX Codex +1 478installs 121-java-object-oriented-design Reviews Java code against SOLID, DRY and YAGNI, flags God Class and Feature Envy, and applies small refactorings. Useful when reworking an object model. CX Codex +1 469installs 131-java-testing-unit-testing Reviews and improves Java unit tests using JUnit 5, AssertJ, and Mockito. It catches testing anti-patterns and verifies boundary conditions. CX Codex +1 449installs 125-java-concurrency A skill that has your coding agent review Java code for race conditions, lock contention and thread leaks, then apply modern java.util.concurrent fixes. CX Codex +1 402installs 122-java-type-design A skill that reviews and refactors Java code for type design: kills primitive obsession, builds type hierarchies, picks BigDecimal where precision matters. CX Codex +1 394installs 302-frameworks-spring-boot-rest A skill that guides an agent through designing and reviewing Spring Boot REST APIs: methods, status codes, DTOs, versioning, pagination, RFC 7807 errors. CX Codex +1 392installs 301-frameworks-spring-boot-core Enforces constructor injection and fail-fast config validation in Spring Boot 4.0.x codebases with strict Maven verification. CX Codex +1 390installs 111-java-maven-dependencies Adds code-quality Maven dependencies to your pom.xml: JSpecify, Error Prone with NullAway, VAVR, ArchUnit, JavaMoney. Asks what you need and installs only that. CX Codex +1 388installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor