AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with Eclipse and Enum's

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
MrFredBloggs@hotmail.com
Guest





PostPosted: Thu Apr 21, 2005 11:55 pm    Post subject: Problem with Eclipse and Enum's Reply with quote



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.

Back to top
Peter MacMillan
Guest





PostPosted: Fri Apr 22, 2005 6:43 pm    Post subject: Re: Problem with Eclipse and Enum's Reply with quote



[email]MrFredBloggs (AT) hotmail (DOT) com[/email] wrote:
Quote:
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/communityprocess/jsr/tiger/enum.html
and
http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html


--
Peter MacMillan
e-mail/msn: [email]peter (AT) writeopen (DOT) com[/email]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.