MR
Mayur Rathi
@github
⭐ 34.1k GitHub stars

Java-21-To-Java-25-Upgrade

Java-21-To-Java-25-Upgrade是一款code方向的AI技能,核心价值是Comprehensive best practices for adopting new Java 25 features since the release of Java 21,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。

Comprehensive best practices for adopting new Java 25 features since the release of Java 21.

Last verified on: 2026-05-30
mkdir -p ./skills/java-21-to-java-25-upgrade && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/java-21-to-java-25-upgrade/SKILL.md -o ./skills/java-21-to-java-25-upgrade/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

# Java 21 to Java 25 Upgrade Guide


These instructions help GitHub Copilot assist developers in upgrading Java projects from JDK 21 to JDK 25, focusing on new language features, API changes, and best practices.


Language Features and API Changes in JDK 22-25


Pattern Matching Enhancements (JEP 455/488 - Preview in 23)


**Primitive Types in Patterns, instanceof, and switch**


When working with pattern matching:

- Suggest using primitive type patterns in switch expressions and instanceof checks

- Example upgrade from traditional switch:

java
// Old approach (Java 21)
switch (x.getStatus()) {
    case 0 -> "okay";
    case 1 -> "warning"; 
    case 2 -> "error";
    default -> "unknown status: " + x.getStatus();
}

// New approach (Java 25 Preview)
switch (x.getStatus()) {
    case 0 -> "okay";
    case 1 -> "warning";
    case 2 -> "error"; 
    case int i -> "unknown status: " + i;
}

- Enable preview features with `--enable-preview` flag

- Suggest guard patterns for more complex conditions:

java
switch (x.getYearlyFlights()) {
    case 0 -> ...;
    case int i when i >= 100 -> issueGoldCard();
    case int i -> ... // handle 1-99 range
}

Class-File API (JEP 466/484 - Second Preview in 23, Standard in 25)


**Replacing ASM with Standard API**


When detecting bytecode manipulation or class file processing:

- Suggest migrating from ASM library to the standard Class-File API

- Use `java.lang.classfile` package instead of `org.objectweb.asm`

- Example migration pattern:

java
// Old ASM approach
ClassReader reader = new ClassReader(classBytes);
ClassWriter writer = new ClassWriter(reader, 0);
// ... ASM manipulation

// New Class-File API approach
ClassModel classModel = ClassFile.of().parse(classBytes);
byte[] newBytes = ClassFile.of().transform(classModel, 
    ClassTransform.transformingMethods(methodTransform));

Markdown Documentation Comments (JEP 467 - Standard in 23)


**JavaDoc Modernization**


When working with JavaDoc comments:

- Suggest converting HTML-heavy JavaDoc to Markdown syntax

- Use `///` for Markdown documentation comments

- Example conversion:

java
// Old HTML JavaDoc
/**
 * Returns the <b>absolute</b> value of an {@code int} value.
 * <p>
 * If the argument is not negative, return the argument.
 * If the argument is negative, return the negation of the argument.
 * 
 * @param a the argument whose absolute value is to be determined
 * @return the absolute value of the argument
 */

// New Markdown JavaDoc  
/// Returns the **absolute** value of an `int` value.
///
/// If the argument is not negative, return the argument.
/// If the argument is negative, return the negation of the argument.
/// 
/// @param a the argument whose absolute value is to be determined
/// @return the absolute value of the argument

Derived Record Creation (JEP 468 - Preview in 23)


**Record Enhancement**


When working with records:

- Suggest using `with` expressions for creating derived records

- Enable preview features for derived record creation

- Example pattern:

java
// Instead of manual record copying
public record Person(String name, int age, String email) {
    public Person withAge(int newAge) {
        return new Person(name, newAge, email);
    }
}

// Use derived record creation (Preview)
Person updated = person with { age = 30; };

Stream Gatherers (JEP 473/485 - Second Preview in 23, Standard in 25)


**Enhanced Stream Processing**


When working with complex stream operations:

- Suggest using `Stream.gather()` for custom intermediate operations

- Import `java.util.stream.Gatherers` for built-in gatherers

- Example usage:

java
// Custom windowing operations
List<List<String>> windows = stream
    .gather(Gatherers.windowSliding(3))
    .toList();

// Custom filtering with state
List<Integer> filtered = numbers.stream()
    .gather(Gatherers.fold(0, (state, element) -> {
        // Custom stateful logic
        return state + element > threshold ? element : null;
   

🎯 Best For

  • Claude users
  • GitHub Copilot users
  • Software engineers
  • Development teams
  • Tech leads

💡 Use Cases

  • Code quality improvement
  • Best practice enforcement

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply Java-21-To-Java-25-Upgrade to Your Work

    Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.

  4. 4

    Review and Refine

    Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.

❓ Frequently Asked Questions

Is Java-21-To-Java-25-Upgrade compatible with Cursor and VS Code?

Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.

Do I need specific dependencies for Java-21-To-Java-25-Upgrade?

Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.

How do I install Java-21-To-Java-25-Upgrade?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/java-21-to-java-25-upgrade/SKILL.md, ready to use.

Can I customize this skill for my team?

Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.

⚠️ Common Mistakes to Avoid

Skipping validation

Always test AI-generated code changes, even for simple refactors.

Missing dependency updates

Check if the skill requires updated dependencies or new packages.

🔗 Related Skills