Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

enum type declaration error

Thread view: 
akarui.tomodachi@gmail.com - 18 Dec 2006 04:59 GMT
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
frikk - 18 Dec 2006 05:08 GMT
First of all, is the code missing a ; after the enum declaration line?

Blaine

On Dec 17, 11:59 pm, akarui.tomoda...@gmail.com wrote:
> I came from C domain and learning JAVA.
> I believe, there is C equivalent "enum" type existed in JAVA. But my
[quoted text clipped - 46 lines]
>
> }//myHelloWorld class
akarui.tomodachi@gmail.com - 18 Dec 2006 05:17 GMT
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?
>
[quoted text clipped - 51 lines]
> >
> > }//myHelloWorld class
John Ersatznom - 18 Dec 2006 05:46 GMT
> 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)
Hemal  Pandya - 18 Dec 2006 05:50 GMT
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.
[quoted text clipped - 9 lines]
> > > understand where I made mistake. Note that, I am using the latest GCC
> > > compiler for JAVA (gcj).
[....]
Daniel Pitts - 18 Dec 2006 06:12 GMT
> I came from C domain and learning JAVA.
> I believe, there is C equivalent "enum" type existed in JAVA. But my
[quoted text clipped - 45 lines]
>     }//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.
IchBin - 18 Dec 2006 18:32 GMT
> I came from C domain and learning JAVA.
> I believe, there is C equivalent "enum" type existed in JAVA. But my
[quoted text clipped - 45 lines]
>     }//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

Signature

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-)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.