tags:

views:

63

answers:

2
public enum ItemType{REFRENCE,ISSUE};
    ItemType itemType =  IntemType.ISSUE ;
    int intemNo=0;

I am geting error wheni use above code?why is it so?

A: 

Did you compile with setting "source java 1.5"? The enum syntax was't supported before java 1.5.

codymanix
when i type java verion at command promt i get the following: java version "1.6.0_11"Java(TM) SE Runtime Environment (build 1.6.0_11-b03)Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
akshay
+3  A: 
  1. The code you provided (still) contains a typo: it's either IntemType or ItemType
  2. Make sure, you use Java 1.5 or later. Earlier versions of Java do not support enums
  3. Make sure, you compile with source level 1.6. It's one of my favourite mistakes in eclipse to use a Java 6 SDK and have a project configured for source level 1.4 ...
  4. Your declaring an interface - an interface can't have fields. Declare it as a class
  5. If none of the above helps - please edit your question and add error details.

Thanks for the comment, from JLS

Every field declaration in the body of an interface is implicitly public, static, and final.

Andreas_D
You cant declare a public enum and a public class/interface in the same file. (Is that correct?)
jjnguy
Also, the enum declaration shouldn't end wit ha semicolon.
jjnguy
(I would edit your answer myself, but I'm not 100% sure about those.
jjnguy
An interface can have fields, they're just final by default. The enum is fine in there, too, though unnecessary.
wds
am using java version "1.6.0_11"
akshay
Actually they're necessarily final, not just by default. You guys don't remember the bad old days when people used interfaces to emulate singletons?
wds
@Justin, you can only have one _top level_ public class in the same file, but it may contain as many public inner classes / enums as you wish (well, up to a technical limit, which might be 255). And the semicolon is unnecessary, but is hardly an error.
Péter Török
@Peter, ok. Glad I didn't edit them in myself...
jjnguy
@Justin - it's obsolete anyway after the last edits of the question ;)
Andreas_D