Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Problem with Eclipse and Enum's
Hi All,

I think that the following code is correct:

public enum Days
{
SUNDAY (1),
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY;
}

However it doesn't compile under Eclipse 3.1M6.

What am I doing wrong?

Fankx,

Fred.


Report this thread to moderator Post Follow-up to this message
Old Post
MrFredBloggs@hotmail.com
04-22-05 08:58 AM


Re: Problem with Eclipse and Enum's
MrFredBloggs@hotmail.com wrote:
> Hi All,
>
> I think that the following code is correct:
>
> public enum Days
> {
>     SUNDAY (1),
>     MONDAY,
>     TUESDAY,
>     WEDNESDAY,
>     THURSDAY,
>     FRIDAY,
>     SATURDAY;
> }
>
> However it doesn't compile under Eclipse 3.1M6.
>
> What am I doing wrong?
>
> Fankx,
>
> Fred.
>

Your code is wrong.

MONDAY is equivlant to MONDAY() - the default constructor.

Remember that, when you create a class, you get a default empty
constructor unless you specify one (or the superclass excludes an empty
constructor).

You don't really want SUNDAY to equal 1. You want SUNDAY to equal SUNDAY
and that's what enums are for.

You might want something like:

public enum Day
{
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY;
}


and then somewhere in code:

for (Day day : Day.values()) {
System.out.println(day.name());
}

The order of values() is guaranteed to be the same as the order the
elements are defined in the enumeration.

see:
http://jcp.org/aboutJava/communityp...tiger/enum.html
and
http://java.sun.com/j2se/1.5.0/docs...uage/enums.html


--
Peter MacMillan
e-mail/msn: peter@writeopen.com

Report this thread to moderator Post Follow-up to this message
Old Post
Peter MacMillan
04-23-05 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:23 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.