• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Enum  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me why this does not work and how to fix it

private enum GuessedValue{A,2,3,4,5,6,7,8,9,J,Q,K}

I think it sees it as both integers and chars
 
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing -- in the absence of any error messages (surely you must have got something from the compiler?) -- that "2" isn't a valid identifier.
 
Greenhorn
Posts: 9
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul said it right. Along with this you can not have a private enum, it can be only public.
 
Tom Orr
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes the compiler tells me an identifier is expected for the integers. I changed it to public and still get the same message.

Im going to try going another direction with this.

my enum will be public and contain {ACE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,JACK,QUEEN,KING}

 
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can read about identifiers here.
 
Tom Orr
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK got it, Here is where I am now. Why do I get an incompatible type error on lines 32 and 33. And how can I make it so it assigns the value it pulls from the string to my enum?

 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, substring returns a string, and neither guessedSuit nor guessedValue are of that type. So that's why you get an incompatible type message.
 
Tom Orr
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a way to convert it from a string to my enum type? Like the wrapper classes?
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I started to show you how I would do it in Java, and come to find out that Java has this built-in:



And that returns the right Enum of type Value.

In case you aren't aware of it (I wasn't), v.toString() will do the reverse -- return the String declared as the enum constant.

I recommend http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Enum.html -- lots of good stuff in there.

rc
 
Sheriff
Posts: 21461
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, toString() can be overridden to return something else. v.name() will always return the actual name, as it's a final method in java.lang.Enum.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!