Content deleted Content added
No edit summary |
Reply to enum concerns |
||
Line 10:
As far as I recall, this is false. C# uses the <code>enum</code> keyword, whereas Java uses a Class ([http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Enum.html link java.lang.Enum]) introduced in Java 1.5. I haven't edited the page to reflect this, as I am unsure and would like confirmation first.
In Java 5.0 enums are lower case, like types, and have their own syntax.
<code>
private enum Coin {
penny(1), nickel(5), dime(10), quarter(25);
Coin(int value) { this.value = value; }
private final int value;
public int value() { return value; }
}
</code>
Also enums can be used in switches. Classes cannot be used this way.
<code>
switch(menu) {
case FILE:
System.out.println("FILE Menu");
break;
case EDIT:
System.out.println("EDIT Menu");
break;
case FORMAT:
System.out.println("FORMAT Menu");
break;
case VIEW:
System.out.println("VIEW Menu");
break;
}
</code>
Check out
http://java.sun.com/developer/technicalArticles/releases/j2se15langfeat/
http://zamples.com/JspExplorer/samples/jdk1_5.jsp
http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html
In Java even arrays are technically classes ie
<code>
Object o = new int[10];
</code>
Further compiling:
<code>
public class Test {
private int enum = 10;
}
</code>
Yields the error:
<code>
Test.java:2: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
(try -source 1.4 or lower to use 'enum' as an identifier)
private int enum = 10;
^
1 error
</code>
My inclination is to call it a keyword, because of the new syntax, and the compiler error.
[[User:Tbjablin|Tbjablin]] 04:34, 9 Mar 2005 (UTC)
|