enum type declaration error

A

akarui.tomodachi

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
 
A

akarui.tomodachi

Sorry, it was my "copy and paste" mistake. But the ";" at the end of
declaration didn't help. I am still getting the same error.
First of all, is the code missing a ; after the enum declaration line?

Blaine

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
 
J

John Ersatznom

Sorry, it was my "copy and paste" mistake. But the ";" at the end of
declaration didn't help. I am still getting the same error.

Does the compiler you're using support Java 5? (AKA Java 1.5, 1.5.0, and
Tiger)
 
H

Hemal Pandya

Does gcj support the changes introduced by Java 5? I can't find any
specific reference that it does.

Sorry, it was my "copy and paste" mistake. But the ";" at the end of
declaration didn't help. I am still getting the same error.
[....]
 
D

Daniel Pitts

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.
 
I

IchBin

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

1 - Code Conventions for the Java Programming Language
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

2 - Enums 1.5.0
http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA
______________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top