JAVA项目中enum+switch的用法

Enum类
public enum ServiceTypeEnum {
    DEPLOYMENT,STATEFULSET
}
 
方法中使用:
serviceType = deployment;
ServiceTypeEnum typeEnum = ServiceTypeEnum.valueOf(serviceType.toUpperCase());
        switch (typeEnum){
            case DEPLOYMENT:
                ...
                break;
            case STATEFULSET:
                ...
                break;
            default:
                break;
        }

因为switch的case这里,不能使用enum的字符串值,如果使用 枚举值.字符串值 ,那么会提示 Constant expression required

猜你喜欢

转载自blog.csdn.net/yangyangrenren/article/details/115350988