Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

const — reserved unused keyword

const — reserved unused keyword: const is a reserved but unused Java keyword; it declares no constant and cannot be used as an identifier.

Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime

Syntax

const

const is a reserved but unused Java keyword; it declares no constant and cannot be used as an identifier.

Declare constants with final, commonly static final for class values; SourceVersion.isKeyword lets tools recognize const for a language release.

Porting a C or JavaScript const declaration causes a Java syntax error, and naming a variable const also fails compilation.

Reservation applies despite having no runtime semantics; the string literal "const" and identifiers containing it, such as constant, remain legal.

For Java 21, SourceVersion returns true for isKeyword("const") and false for isName, proving reservation without invalid source.

Examples

import javax.lang.model.SourceVersion;

public class Main {
    public static void main(String[] args) {
        var release = SourceVersion.RELEASE_21;
        System.out.println(SourceVersion.isKeyword("const", release));
        System.out.println(SourceVersion.isName("const", release));
    }
}

Result

true
false

For Java 21, SourceVersion returns true for isKeyword("const") and false for isName, proving reservation without invalid source.

Sources