Can a Java package name be a keyword?

When I try to create an implements package using Intellij (community publication), I received a message Not a valid package name . Is it because of using a keyword?

enter image description here

+6
source share
4 answers

Is it because of using a keyword?

Yes, the package name has the following form

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

where is the Identifier

 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.

+18
source

You cannot use the java keyword in your package declaration.

 abstract continue for new switch assert default if package synchronized boolean do goto private this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const float native super while 

These keyworkds cannot be used.

package declaration syntax

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

Here, identifiers are any Unicode character that is a "Java letter" or any Unicode character that is a "Java letter or number."
"Java letters" include uppercase and lowercase Latin letters ASCII AZ (\ u0041- \ u005a) and az (\ u0061- \ u007a), and for historical reasons, the underscore is ASCII (_, or \ u005f) and the dollar sign ($, or \ u0024). The $ sign should only be used in mechanically generated source code, or, less commonly, to access existing names in legacy systems.

Contact

+2
source

You cannot use the Java keyword as the package name. See JLS by Name and Identifiers

+2
source

This works fine for me in Intellij 13.1.2, however you cannot use a package with that name even if you create it because the java package statement does not accept the keyword anywhere in the package names. So, I can create, but I can not use:

 package com.implements.thing; 
+1
source

All Articles