Enum within an enum

前端 未结 3 576
轻奢々
轻奢々 2020-12-03 09:42

This isn\'t a matter of me being stuck, but rather I\'m looking for a tidy way to write my code.

Essentially, I\'m writing an event driven application. The user trig

3条回答
  •  我在风中等你
    2020-12-03 10:38

    I believe that in Java, you can simply nest enums, as long as your non-enum constants come first.

    enum Action
    {
        FOO,
        BAR;
        enum MOVE
        {
             UP,
             DOWN,
             LEFT,
             RIGHT 
        }
    }
    

    This compiles for me and gives me the behavior you were looking for.

提交回复
热议问题