java 8: difference between class.getName() and String literal [duplicate]
问题 This question already has answers here : Java switch statement: Constant expression required, but it IS constant (13 answers) Closed 4 years ago . I was working on switch case. If we use class.getName(), then, I am getting error that "case expressions must be constant expressions" as follows: switch(param.getClass().getName()) { case String.class.getName(): // to do break; } Even if we do following, take string class name in a constant, then also, getting same error: public static final