Switch Statement gives Incompatible Types error

前端 未结 5 1053
长发绾君心
长发绾君心 2020-12-11 03:25

I am trying to compile and I get this error:

enigma/Rotor.java:30: incompatible types found : java.lang.String required: int     switch(name){
1 error
         


        
5条回答
  •  臣服心动
    2020-12-11 03:41

    switch(name)
    

    switch statement with String is supported from Java7 onwards only.

    I guess the compiler version you are using is less than Java7

    Options:

    1. You need to either upgrade to Java7
    2. Change switch statement to if/else
    3. Use int in switch instead of String

提交回复
热议问题