aspose file tools*
The moose likes Beginning Java and the fly likes Can't get enum to work. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Can't get enum to work.

Oliver Tatlow
Greenhorn

Joined: Jul 17, 2012
Posts: 5


Getting error "Cannot find symbol" in line a=Monday and can't understand why.

Have tried moving the declaration of enum WEEKDAYS into every possible scope but still doesn't work. Even tried putting the enum declaration in a separate file as a public enum. Please can anyone tell me where this is wrong.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

Hello Oliver Tatlow,

Welcome to CodeRanch!

Its good to see that you've started using code tags quite early.

Now, coming to your question:

Hint : How would compiler know that member 'MONDAY' belongs to enum 'WeekDays'? What do you think?


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Waldemar Macijewski
Ranch Hand

Joined: Jun 22, 2012
Posts: 32
I'm going to say my worthless opinion here, but before I post something on the forums, I usually do my homework just within a few clicks you would have all the info you need. But anyway, here's what I have learned about enumerations: All enumeration constants are actually objects of it's enumeration type. All enums automatically inherit java.lang.Enum class, which has predefined methods like Ordinal() & compareTo(), so all of your constants will have access to those methods. Enumerations act like classes, although you don't initiate enums with new , you simply create referance variable of the enum type: SomeEnum a; . As you might guess, each object in enum is implicitly final. , so you usually assign value using constructor lie this:


then when you create variable of enum type, constructor will be called for each constant in enum. You can print value of each constant, just like you do with static members EnumName.Member . Also, you can use enum constants to control switch statement.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Okti Wm wrote: just like you do with static members EnumName.Member .


That's actually the answer right there.


Junilu - [How to Ask Questions] [How to Answer Questions]
Oliver Tatlow
Greenhorn

Joined: Jul 17, 2012
Posts: 5
Anayonkar Shivalkar wrote:Hello Oliver Tatlow,

Welcome to CodeRanch!

Its good to see that you've started using code tags quite early.

Now, coming to your question:

Hint : How would compiler know that member 'MONDAY' belongs to enum 'WeekDays'? What do you think?


I have no idea.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

You have been given ample clues. Think!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Oliver Tatlow
Greenhorn

Joined: Jul 17, 2012
Posts: 5
Bear Bibeault wrote:You have been given ample clues. Think!


I was looking for an answer, not clues.

If you haven't got anything useful to add then please don't bother posting on my threads, thanks.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1021
    
    5

Oliver

just like you do with static members EnumName.Member


This is the clue everyone is referring to.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Oliver Tatlow wrote:
Bear Bibeault wrote:You have been given ample clues. Think!


I was looking for an answer, not clues.

If you haven't got anything useful to add then please don't bother posting on my threads, thanks.

That's not how things work around here, I'm afraid. There are certain things you should know about this community to understand why you're getting the kind of replies you're getting. Start with these pages: NotACodeMill (<--click) and ShowSomeEffort (<--click).
Bill Clar
Ranch Hand

Joined: Sep 21, 2006
Posts: 152

Oliver Tatlow wrote:
Bear Bibeault wrote:You have been given ample clues. Think!


I was looking for an answer, not clues.

If you haven't got anything useful to add then please don't bother posting on my threads, thanks.


Oliver, Bear is being useful. He's trying to get you to ShowSomeEffort (<- Click).
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

Oliver Tatlow wrote:I was looking for an answer, not clues.

Then you are in the wrong place.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Oliver Tatlow, I do not wish to be rude or anything, nor to repeat what everybody else has explained to you. You learn a lot better by doing things yourself.

I think I shall prevent more annoyance for all concerned and draw a line under this event by writing what the newspaper editor would:
This correspondence now closed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't get enum to work.