1

How can I make a hierarchical structure with Java enum? For example, I have following levels:

Level- [Level1, Level2]
Level1 - [Level1_1, Level1_2, Level1_3] 
Level2 - [Level2_1, Level2_2] 

Can I create an enum 'Levels' like below, so I can access it using Level.Level1.Level1_1 or Level.Level2.Level2_2 etc, Sub-levels should be accessed via its parent:

public enum Levels {
    Level1 {
        Level1_1,
        Level1_2,
        Level1_3
    },
    Level2 {
        Level2_1,
        Level2_2,
    }
}
Jerrybibo
  • 1,315
  • 1
  • 21
  • 27
suraj bahl
  • 2,864
  • 6
  • 31
  • 42

0 Answers0