Re: Smuggling information to enums
On Mar 24, 10:57 am, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
What the techniques are there for smuggling information to enums?
they don't have constructors. It is not clear how you would make
them nested classes.
Is it possible to somehow have two enum class objects in RAM at once,
each with different instance data?
Do you have to pass it in each time with the method or use static
setters?
--
Roedy Green Canadian Mind Productshttp://mindprod.com
"Nature provides a free lunch, but only if we control our appetites."
~ William Ruckelshaus, America's first head of the EPA
I'm not sure what you mean by "smuggling" information.
Enums can have constructors, though. See the following example (this
enum is inside the class ActionManager):
public enum DefaultActions {
CASCADE_WINDOW_ACTION(new CascadeWindowsAction()),
CLOSE_ALL_PROJECTS_ACTION(new CloseAllProjectsAction()),
CLOSE_ALL_WINDOWS_ACTION(new CloseAllWindowsAction());
// There are more actions, I'm just truncating it for posting
purposes.
/**
* Constructor
*
* @param action
* the action to place into the manager
*/
private DefaultActions(AbstractAction action) {
String key = this.toString();
ActionManager.put(key, action);
}
/**
* Convenience method for retrieving a default action.
*
* @return the action
*/
public AbstractAction getAction() {
return ActionManager.get(this.toString());
}
}