Search code examples
javaintellij-ideapackagekeyword

Can Java package name be a keyword?


When I try to create a package named implements using IntelliJ (community edition), I got a message which says "Not a valid package name". Is this because of the keyword being used?

enter image description here


Solution

  • Is this because of the keyword being used?

    Yes, a package name has the following form

    PackageDeclaration:
        {PackageModifier} package Identifier {. Identifier} ;
    

    where Identifier is

    Identifier:
        IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
    IdentifierChars:
        JavaLetter {JavaLetterOrDigit}
    JavaLetter:
        any Unicode character that is a "Java letter"
    JavaLetterOrDigit:
        any Unicode character that is a "Java letter-or-digit"
    

    So keywords cannot be used.