14

141-java-refactoring-with-modern-features

Modernizes Java code by applying Stream API, Optional, java.time, and modern language features.

Install

mkdir -p .claude/skills/141-java-refactoring-with-modern-features && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16141" && unzip -o skill.zip -d .claude/skills/141-java-refactoring-with-modern-features && rm skill.zip

Installs to .claude/skills/141-java-refactoring-with-modern-features

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

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. Part of cursor-rules-java project
609 chars✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Intermediate

Key capabilities

  • Migrate anonymous classes to lambda expressions
  • Replace Iterator loops with Stream API
  • Adopt Optional for null safety
  • Switch from legacy Date/Calendar to java.time
  • Use unmodifiable collection factory methods
  • Apply text blocks for multi-line strings

How it works

This skill identifies and applies modern Java (Java 8+) refactoring opportunities by replacing legacy idioms with contemporary features like lambdas, Stream API, and java.time, while ensuring compilation and verification.

Inputs & outputs

You give it
Legacy Java code (Java 8+)
You get back
Refactored Java code using modern features, with behavior preserved

When to use 141-java-refactoring-with-modern-features

  • Refactor to Streams
  • Adopt Optional for null safety
  • Migrate to java.time

About this skill

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.

  1. 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.

  1. Apply modern Java refactorings

Refactor incrementally using appropriate language/library features while preserving behavior and readability.

  1. 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.

When not to use it

  • If the project does not compile before refactoring
  • If the request scope is ambiguous
  • If required inputs, files, or tooling are missing

Limitations

  • Requires the project to compile before applying changes
  • Requires full verification after applying improvements
  • Requires reading the reference for detailed examples and safeguards

How it compares

This skill systematically modernizes Java code by applying specific feature replacements, unlike a manual refactoring process that might miss opportunities or introduce errors.

Compared to similar skills

141-java-refactoring-with-modern-features side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
141-java-refactoring-with-modern-features (this skill)02moNo flagsIntermediate
jakarta-namespace26moReviewIntermediate
spring-boot-migration16moReviewAdvanced
minecraft-bukkit-pro904moNo flagsAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

jakarta-namespace

benchflow-ai

Migrate Java EE javax.* imports to Jakarta EE jakarta.* namespace. Use when upgrading to Spring Boot 3.x, migrating javax.persistence, javax.validation, javax.servlet imports, or fixing compilation errors after Jakarta EE transition. Covers package mappings, batch sed commands, and verification steps.

25

spring-boot-migration

benchflow-ai

Migrate Spring Boot 2.x applications to Spring Boot 3.x. Use when updating pom.xml versions, removing deprecated JAXB dependencies, upgrading Java to 17/21, or using OpenRewrite for automated migration. Covers dependency updates, version changes, and migration checklist.

11

minecraft-bukkit-pro

sickn33

Master Minecraft server plugin development with Bukkit, Spigot, and Paper APIs. Specializes in event-driven architecture, command systems, world manipulation, player management, and performance optimization. Use PROACTIVELY for plugin architecture, gameplay mechanics, server-side features, or cross-version compatibility.

9078

java-coding-standards

affaan-m

Java coding standards for Spring Boot services: naming, immutability, Optional usage, streams, exceptions, generics, and project layout.

1669

springboot-tdd

affaan-m

Test-driven development for Spring Boot using JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo. Use when adding features, fixing bugs, or refactoring.

531

gen-ut

apache

Generate standard unit tests for one or more target classes in Apache ShardingSphere; use unified rules to make target classes reach 100% class/line/branch coverage and pass quality gates.

12

Search skills

Search the agent skills registry