Java enumeration using enumeration in constructor
•
Java
Can I have enumerations in Java take a set of enumerations as parameters? If so, how can I achieve it?
When I use this, what I want to say is: take a modal_ SETTINGS. EDIT_ MODAL_ Windows and use modal_ BUTTONS. Save & button to create it MODAL_ BUTTONS. CANCEL.
This is what I have now
public enum MODAL_SETTINGS { NEW_MODAL_WINDOW(MODAL_BUTTONS.class),EDIT_MODAL_WINDOW(MODAL_BUTTONS.class),DELETE_MODAL_WINDOW(MODAL_BUTTONS.class); private EnumSet buttons; private MODAL_SETTINGS(EnumSet<MODAL_BUTTONS> buttons){ } } public enum MODAL_BUTTONS { SAVE,UPDATE,CANCEL,DELETE }
Solution
Not this:
NEW_MODAL_WINDOW(MODAL_BUTTONS.class),
I suspect you want this:
NEW_MODAL_WINDOW(EnumSet.allOf(MODAL_BUTTONS.class))
or
NEW_MODAL_WINDOW(EnumSet.of(MODAL_BUTTONS.SAVE,MODAL_BUTTONS.CANCEL))
(wait)
Otherwise, you just pass a class < T > instead of an enumset
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码