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 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
On 21 Apr 2005 17:00:18 -0700, MrFredBloggs@hotmail.com wrote:

>Hi All,
>
>I think 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.

The following works but I don't know why your version doesn't work.

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

--Steve

Report this thread to moderator Post Follow-up to this message
Old Post
Steven
04-22-05 08:58 AM


Re: Problem with Eclipse and Enum's
On Fri, 22 Apr 2005 00:46:08 GMT, Steven <steven.green30@verizon.net>
wrote:

>On 21 Apr 2005 17:00:18 -0700, MrFredBloggs@hotmail.com wrote:
> 
>
>The following works but I don't know why your version doesn't work.
>
>public enum Day {
>	SUNDAY(1),
>	MONDAY,
>	TUESDAY,
>	WEDNESDAY,
>	THURSDAY,
>	FRIDAY,
>	SATURDAY;
>	public Day() {}
>	public Day(int i) {}
>}
>
>--Steve

Ok based on the examples in
http://jcp.org/aboutJava/communityp...tiger/enum.html I would
say it is behaving correctly. It gives an example using a Coin enum as
follows:

public enum Coin {
penny(1), nickel(5), dime(10), quarter(25);

Coin(int value) { this.value = value; }

private final int value;

public int value() { return value; }
}

This example uses the Coin(int) constuctor for every entry. Your
version requires the Day() and Day(int) because you are using two
types of declarations. It may be that what you want is something along
the lines of the following:

public enum Day {
Sun(1),
Mon(2),
Tue(3),
Wed(4),
Thr(5),
Fri(6),
Sat(7);

private final int value;
public int value() { return value; }
}

Having used a simpler form myself, this seems a little more than is
wanted.

--Steve

Report this thread to moderator Post Follow-up to this message
Old Post
Steven
04-22-05 08:58 AM


Re: Problem with Eclipse and Enum's
I tried the following and it worked.

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

It uses private constructors though, according to Eclipse, public ones
aren't allowed (is that correct, must they always be private?).

Fankx for the help,

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
On 21 Apr 2005 18:15:28 -0700, MrFredBloggs@hotmail.com wrote:

>I tried the following and it worked.
>
>public enum Days
>{
>        SUNDAY(1),
>        MONDAY,
>        TUESDAY,
>        WEDNESDAY,
>        THURSDAY,
>        FRIDAY,
>        SATURDAY;
>        private Days() {}
>        private Days(int i) {}
>}
>
>It uses private constructors though, according to Eclipse, public ones
>aren't allowed (is that correct, must they always be private?).
>
>Fankx for the help,
>
>Fred.
To start off, Eclipse didn't seem to care that the constructors were
public or private, not sure if that matters or not.

I don't know the answer to my following question, but I am taking a
guess based upon the example implementation.

Enums in Java seem as though they don't have a particular value. For
example Days.SUNDAY doesn't equal 1. I may be wrong and hope if
someone else has a better information they will post it. They appear
to be more complicated than the C++ cousines.

I am not sure if this implementation with empty constructor calls is
really what you have in mind.

Just thinking out loud.
--Steve


Report this thread to moderator Post Follow-up to this message
Old Post
Steven
04-22-05 09:01 PM


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:28 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.