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?
This is not possible with Java, because each item has to be a valid identifier (and valid Java identifiers may not contain dashes).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With