Bookmark Topic Watch Topic
  • New Topic

Can't get enum to work.

 
Oliver Tatlow
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator


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
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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?
 
Waldemar Macijewski
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Okti Wm wrote: just like you do with static members EnumName.Member .


That's actually the answer right there.
 
Oliver Tatlow
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 64175
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
You have been given ample clues. Think!
 
Oliver Tatlow
Greenhorn
Posts: 5
  • 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Oliver

just like you do with static members EnumName.Member


This is the clue everyone is referring to.
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 163
Eclipse IDE Java Tomcat Server
  • 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 12015
24
Chrome Java Linux
  • 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Oliver Tatlow wrote:I was looking for an answer, not clues.

Then you are in the wrong place.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic