Java enum : Refactoring switch statements 'constant expression required' compile error?

前端 未结 4 1810
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 05:41

I have a class declaring constants for my app

public class GroupConstants {
    ..
    public static final int INTEGER_VALUE = 1;
    public static final int         


        
4条回答
  •  情深已故
    2020-12-29 06:13

    Try getting rid of the GroupConstants. prefix in your case statements. For reasons completely unclear to me, it doesn't accept the same constant if it's prefixed with class name.

    So instead of

     case GroupConstants.STRING_VALUE:
    

    please try:

     case STRING_VALUE:
    

    You might need a static import to make it compile.

提交回复
热议问题