set of "differenet" enums

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tassos Souris
    New Member
    • Aug 2008
    • 152

    set of "differenet" enums

    Hi!

    in Effective Java (don't rememember item number) i read that
    a enum set can be used to group together "flags" that are to be set somewhere, example:

    Code:
    public class Text{
        public enum Style{ BOLD, ITALIC, ... }
    
        public void applyStyles(Set<Style> styles) { ... }
    }
    
    ... and we apply the styles in user code as: ...
    
    text.applyStyles(EnumSet.of(Style.BOLD));

    can i use a similar trick if the enumerations cannot be arbitraly mixed? Here we can pass any combination of the Style enum values... However if i have a enum A{ a1, a2, b1, b2 }
    and the combinations (a1,a2) and (b1,b2) are not valid what can i use?

    Thanks
Working...