Switch on Enum when strings contain dash
enums, java, switch-statement
Solution
This is not possible with Java, because each item has to be a valid identifier (and valid Java identifiers may not contain dashes).
Problem
I would like to use enum as a way of switching over strings, however java complains as my string contains "-". As seen in the code below where IC19-01 and IC19-02 contain "-". ``` public class CMain { public enum Model { IC19-01, IC19-02 } public static void main(String[] args){ String st = "IC19-01"; switch (Model.valueOf(st)) { case IC19-01: System.out.println("Case IC19-01"); break; } } } ``` What can i do for this?