• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing an enum to & returning a value from a generalized method.  RSS feed

 
Richard Mittleman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I a trying to write a generalize enum evaluator in my class of utilities but can't figure out how to pass the enum nor return the value.

The calling program would have this code in it:

private enum buttonPushed {Add, Change, Delete,Quit,Help, Nothing};
switch (GetButtonFunction(e), buttonPushed)

The called method in my utility class would look like this.

public static someType GetButtonFunction(ActionEvent e, enum theEnum)
{
String nameOnButton = e.getActionCommand();
String firstWordOnButton = nameOnButton;
int spaceIndex = nameOnButton.indexOf(" ");
if (spaceIndex > 0 ) firstWordOnButton = nameOnButton.substring(0, spaceIndex);
someType button = null;
try
{
button = theEnum.valueOf(firstWordOnButton);
}catch(Exception e1)
{
button = theEnum.valueOf("Nothing");
}
return button;

}

What I can't figure out is how to specify someType & enum theEnum.

Any help would be greatly appreciated.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags. Use the edit button to add them.

Check out enum types.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!