Generating Enums Dynamically

后端 未结 4 1890
旧巷少年郎
旧巷少年郎 2020-12-10 02:18

Let\'s say I have a file whose format is basic XML, like so:



    
        SomeEnum<         


        
4条回答
  •  盖世英雄少女心
    2020-12-10 03:08

    Agree with Oscar Lopez. Here is what i did, a sort of hack.

    public static enum Setter {
    
        DYNAMIC_ENUM_EXAMPLE {
    
            @Override
            public String setGetValue(String yourValue) {
                return "prefix " + yourValue + " postfix";
            }
        };
        public abstract String setGetValue(String value);
    }
    

    You can get the value like this :

    Setter.DYNAMIC_ENUM_EXAMPLE.setGetValue("namaste")
    

    Output :

    prefix namaste postfix
    

提交回复
热议问题