Using string representations of enum values in switch-case

前端 未结 3 1523
清酒与你
清酒与你 2020-12-31 04:06

Why is it not possible to use enum values as strings in a switch case? (Or what is wrong with this:)

String argument;
switch (argument) {
    case MyEnum.V         


        
3条回答
  •  清酒与你
    2020-12-31 04:44

    To add to the Peter Lawrey's comments, have a look at this post from last year which discusses Switching on String in Java before and after JDK7.

提交回复
热议问题