Skip to content

Fix guarded-patterns: replace instanceof pattern matching with Java 8 compatible old code#143

Merged
brunoborges merged 3 commits intomainfrom
copilot/update-java-version-guarded-patterns
Mar 25, 2026
Merged

Fix guarded-patterns: replace instanceof pattern matching with Java 8 compatible old code#143
brunoborges merged 3 commits intomainfrom
copilot/update-java-version-guarded-patterns

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

The old code in guarded-patterns used instanceof pattern matching with a binding variable (shape instanceof Circle c), which requires Java 16+ (JEP 394) and is incompatible with the oldLabel: "Java 8" annotation.

Change

  • content/language/guarded-patterns.yaml: Replaced the old code's instanceof pattern matching syntax with a Java 8 compatible version using an explicit cast.
// Before (Java 16+ only)
if (shape instanceof Circle c) {
    if (c.radius() > 10) {
        return "large circle";
    } else {
        return "small circle";
    }
} else {
    return "not a circle";
}

// After (Java 8 compatible)
if (shape instanceof Circle) {
    Circle c = (Circle) shape;
    if (c.radius() > 10) {
        return "large circle";
    } else {
        return "small circle";
    }
} else {
    return "not a circle";
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI linked an issue Mar 25, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix compilation issue with guarded patterns in Java Fix guarded-patterns oldLabel: "Java 8" → "Java 16" Mar 25, 2026
Copilot AI requested a review from brunoborges March 25, 2026 14:17
@brunoborges
Copy link
Copy Markdown
Member

The old code must be Java 8 compatible @copilot

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 25, 2026

The old code must be Java 8 compatible @copilot

Done in bd016a6 — reverted oldLabel back to "Java 8" and replaced the old code with Java 8 compatible syntax (explicit instanceof check + (Circle) shape cast instead of the pattern matching binding variable).

Copilot AI changed the title Fix guarded-patterns oldLabel: "Java 8" → "Java 16" Fix guarded-patterns: replace instanceof pattern matching with Java 8 compatible old code Mar 25, 2026
@brunoborges brunoborges marked this pull request as ready for review March 25, 2026 17:20
@brunoborges brunoborges merged commit 609d032 into main Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code Issue] Patterns avec gardes when

2 participants