Hierarchical enum in Java
问题 Let's say I have a structure like this: Is it possible to create an enum that will return the string value of selected cell? For example: enum.GROUP_MAIN1.SUBGROUP1.COL1 will return value "COL1" . I was looking for nested enums but didn't find the solution to this situation. 回答1: You can do this with such trick: public interface GROUPMAIN1 { enum SUBGROUP1 implements GROUPMAIN1 { COL1, COL2, COL3 } enum SUBGROUP2 implements GROUPMAIN1 { COL3, COL4 } } So to get enum you will need to use