Re: enum type declaration error




akarui.tomodachi@xxxxxxxxx wrote:
I came from C domain and learning JAVA.
I believe, there is C equivalent "enum" type existed in JAVA. But my
initial experiment is giving compile error as below. Please help me to
understand where I made mistake. Note that, I am using the latest GCC
compiler for JAVA (gcj).

Thanks in advance.

Compile error:
/*****
myHelloWorld.java:8: error: Invalid declaration.
public enum returnStatus {RETURN_TRUE, RETURN_FALSE}
^
myHelloWorld.java:8: confused by earlier errors, bailing out

*****/


My experimental code is as below:
/*
myHelloWorld.java
*/
public class myHelloWorld
{

// Return value definition (public)
public enum returnStatus {RETURN_TRUE, RETURN_FALSE}

// Private method to print something on the console
private returnStatus printSomething()
{
// Return status intialization
returnStatus retValue = new returnStatus;

// Print something on the console
System.out.println("Hi Hello World !");

//Return
retValue = retValue.RETURN_TRUE;
return retValue;

}//printSomething()

// Main method
public static void main(String[] args)
{
printSomething();

}//main()
}//myHelloWorld class

Use a boolean instead :-)

The reality of it, as others have pointed out, is that enums are a Java
1.5 feature. I would check that your compiler supports 1.5 language
features. I don't know about GNU's java support, so I couldn't tell
you OTTOMH.

But, I can give you some naming convension advice.

Classes (like nearly everything in Java) follow the UpperCasaWords
convension. However, unlike members of classes. classes themselves are
usually Capitolized.

Enum types too.


MyHelloWorld vs. myHelloWorld and ReturnStatus vs. returnStatus.

Other then that (and those shouldn't cause compiler errors). I don't
see anything wrong. Perhaps you should consider getting the latest Sun
JDK.

.



Relevant Pages

  • Re: enum type declaration error
    ... there is C equivalent "enum" type existed in JAVA. ... initial experiment is giving compile error as below. ... public enum returnStatus ...
    (comp.lang.java.programmer)
  • Re: Jython inherit from Java class
    ... Compiling .java to .class... ... 'assert' is a keyword, and may not be used as an identifier ... release 1.5, 'enum' is a keyword, and may not be used as an identifier ...
    (comp.lang.python)
  • Re: A class that uses instances of itself? Is this right?
    ... > I was recently sent some Java code that I find VERY odd. ... > public String getText() { ... 'TypeSafe enum' pattern. ... public void aMethodDoingSomethingOnEnum{ ...
    (comp.lang.java.programmer)
  • Re: Magic Numbers dangerous?
    ... > I am not up on recent Java features but I did look at the enum type prior to ... > deciding to use named constants in the example above. ... The elements of an enumeration have nothing to ...
    (comp.lang.java.programmer)
  • Re: Typesafe Enum Pattern
    ... designs in .NET which mirror the equivalent Java enums by using a C# ... you are obviously very passionate about improvements to the enum ... to the type-safe enum pattern to begin with. ... public static readonly ArithmeticOperation Addition = new Add; ...
    (microsoft.public.dotnet.languages.csharp)

Loading