I'm just starting to teach myself Java, and I'm having a terrible time
setting up a simple enum. I'm 99.9% sure the syntax is correct,
because I've checked it with numerous online tutorials, but I still
get errors. Here is my file:
Player.java:
package my.game;
public class Player {
public enum Controller {HUMAN, COMPUTER}
private String name;
private boolean isHuman; //I want to change this to be of type
Controller
private int money;
}
and my errors, all on the line with the enum, are
enum cannot be resolved to a type
Syntax error on token "~", ReferenceType expected (in Eclipse, this
error focuses on H in HUMAN)
Syntax error, insert ";" to complete BlockStatements
Syntax error, insert ";" to complete ClassBodyDeclarations
and the warning
'enum' should not be used as an identifier, since it is a reserved
keyword from source level 5.0 on
Thanks for you help,
Colin
Oliver Wong - 19 Feb 2007 22:33 GMT
> I'm just starting to teach myself Java, and I'm having a terrible time
> setting up a simple enum.
[snip. Error from Eclipse:]
> 'enum' should not be used as an identifier, since it is a reserved
> keyword from source level 5.0 on
"enum" was introduced in Java 1.5 (AKA Java 5). Eclipse is telling you
that you need to set your project to target Java 5 or later if you want to
use it. Presumable, currently your project is targeting Java 1.4 or some
earlier version.
Right click on your project, choose "properties", select "Java
Compiler", set "Compiler compliance level" to "5.0" or some higher value
(e.g. 6.0 will work too).
That'll change your current project to use the new version. If you want
to change all projects to use the new version, click on the "Configure
Workspace Settings..." link to set the version for your entire workspace,
instead of only for individual projects.
- Oliver