Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

error: as of release 1.5, 'enum' is a keyword  RSS feed

 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to run a simple web application using NetBeans from Marty Hall's book Core Servlets and JSPs.

This webapp uses a package called Acme which I downloaded. Also in the webapp I have a number of Applets. But when I try to build the project it gives me the following error:

Compiling 157 source files to C:\NETBEANS Projects\Core Servlets Sample\Chapter 14\ShadowedTextApplet\build\web\WEB-INF\classes
C:\NETBEANS Projects\Core Servlets Sample\Chapter 14\ShadowedTextApplet\src\java\Acme\Psg.java:466: warning: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
(try -source 1.5 to use 'enum' as a keyword)
Enumeration enum = path.elements();

C:\NETBEANS Projects\Core Servlets Sample\Chapter 14\ShadowedTextApplet\src\java\Acme\Psg.java:467: warning: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
(try -source 1.5 to use 'enum' as a keyword)
while ( enum.hasMoreElements() )

Can anybody advise me what I should modify to run this application?

Thanks in advance.
Ricky
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing
Enumeration enum = path.elements();
to
Enumeration elements = path.elements();
 
Andris Jekabsons
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason for the error is that starting from Java 5.0 "enum" is a keyword, just like "class", "int", etc. Just like you are not allowed to name your variable "class", you cannot name it "enum" now. Thus, when migrating from Java 1.4 and earlier to 5.0 and later, you have to change all your variables named "enum" to something else.
 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andris Jekabsons:
The reason for the error is that starting from Java 5.0 "enum" is a keyword, just like "class", "int", etc. Just like you are not allowed to name your variable "class", you cannot name it "enum" now. Thus, when migrating from Java 1.4 and earlier to 5.0 and later, you have to change all your variables named "enum" to something else.


Thanks Marilyn and Andris for this info. I shall try to change the name.

But I was wondering, if I have Java 1.4 on a system, then would this app run.

Thanks
Ricky
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.

Note that it should run now, since the message you're getting is a warning, not an error. But if you try to compile and run it using -source 1.5 or 1.6, (or if you omit the -source option) you will get compile errors.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!