I am in the middle of an android project and was trying to create a new package in it.
com.mycompany.myprojectname.new
Well, Eclipse is not letting me to create it and is showing this error:
Invalid package name. ‘new’ is not a valid Java identifier
I never knew package name has reserved words, which we cannot use. My questions are;
- Is this an Eclipse thing? or a Java thing? I tried a pure Java project (not Android), just to check, but there also I got the same error.
- What are other reserved words that is not allowed?
- Is there any documentation about this?
Advertisement
Answer
Yes, this is a general Java thing.
The list of reserved words can be found here. They are:
JavaScriptabstract continue for new switch
assert default goto package synchronized
boolean do if 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
Documentation on the fact that reserved words can not be used in package names if found in the package naming tutorial, among other places.
The authoritative source is (as always) the Java Language Specification, specifically:
- § 3.9 Keywords and
-
An identifier cannot have the same spelling (Unicode character sequence) as a keyword (§3.9), boolean literal (§3.10.3), or the null literal (§3.10.7), or a compile-time error occurs.