Skip to content

Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: EqualsAvoidNull #15063

@mahfouz72

Description

@mahfouz72

child of #14942
I have read check documentation: https://checkstyle.org/checks/coding/equalsavoidnull.html#EqualsAvoidNull
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words


public class Test {
    void test(Object obj) {
        if (obj instanceof String _) {
            _.equals("s");   // compile time error, Using '_' as a reference is not allowed
        }
    }
}

we can't call equals() on unnamed variables or patterns so this check is not applicable to them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions