Skip to content

Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: Design Checks detected in #14942 #15109

@mahfouz72

Description

@mahfouz72

child of #14942

HideUtilityClassConstructorCheck

doc : https://checkstyle.org/checks/design/hideutilityclassconstructor.html#HideUtilityClassConstructor

Makes sure that utility classes (classes that contain only static methods or fields in their API) do not have a public constructor.

unnamed variables can't be a static field. This is completely unrelated to unnamed variables.


InnerTypeLast

doc: https://checkstyle.org/checks/design/innertypelast.html

Checks nested (internal) classes/interfaces are declared at the bottom of the primary (top-level) class after all init and static init blocks, method, constructor and field declarations.

variable definition in this check appears in class member tokens and unnamed variables can't be class members


InterfaceIsTypeCheck

doc : https://checkstyle.org/checks/design/interfaceistype.html

an interface should describe a type. It is therefore inappropriate to define an interface that does not contain any methods but only constants

variable definition in this check is as an interface member token and unnamed variables can't be interface members.


MutableExceptionCheck

doc: https://checkstyle.org/checks/design/mutableexception.html

Ensures that exception classes (classes with names conforming to some pattern and explicitly extending classes with names conforming to other pattern) are immutable, that is, that they have only final fields.

variable definition in this check refers to the class fields that should be final and unnamed variables can't be class fields.


VisibilityModifierCheck

doc : https://checkstyle.org/checks/design/visibilitymodifier.html

Checks visibility of class members. Only static final, immutable or annotated by specified annotation members may be public

This check checks the visibility of class members and unnamed variables can't be class members.


PS D:\CS\test> cat src/Test.java                                                
public class Test {
    int _ = 0;
}
interface Test2 {
    int _ = 0;
}
PS D:\CS\test> javac src/Test.java                                              
src\Test.java:2: error: underscore not allowed here
    int _ = 0;
        ^
src\Test.java:5: error: underscore not allowed here
    int _ = 0;
        ^
2 errors
PS D:\CS\test> 

Metadata

Metadata

Assignees

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