How to convert string result of enum with overridden toString() back to enum?

后端 未结 6 837
醉话见心
醉话见心 2021-01-31 10:30

Given the following java enum:

public enum AgeRange {

   A18TO23 {
        public String toString() {        
            return \"18 - 23\";
        }
    },
          


        
6条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 11:10

    You could always create a map from string to value - do so statically so you only need to map it once, assuming that the returned string remains the same over time. There's nothing built-in as far as I'm aware.

提交回复
热议问题