• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

call an enumeration

 
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
if I have the getter:

public X getX() {
return x;
}

and the enumeration :

public enum X {


OTHER("Other"),
FAX("Fax"),
UNDEFINED("Undefined");

¿how I can get Fax?

Any idea, please?

Regards,
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean, how do you get the string "Fax" from X.FAX?

That's going to depend on the rest of the code you haven't shown. The line FAX("Fax") indicates that the enumeration has a constructor that takes a String argument. I think it's likely that argument gets assigned to a member variable, and I'd expect there to be a getter method for that variable. Then you use that. So you might use something like X.FAX.getLabel() - or getX().getValue() to call your method and get the label from it.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote: I think it's likely that argument gets assigned to a member variable, and I'd expect there to be a getter method for that variable.


@Isaac: And if that member variable is the 'x' you refer to, then you should seriously consider giving it a more meaningful name.
 
reply
    Bookmark Topic Watch Topic
  • New Topic