Java中的枚举开关:未限定的枚举常量

4

我有这个枚举:

public class RemoteUnitType implements Serializable {

    public enum deviceVersion {
        ANDROID_AT1, 
        ANDROID_AT1_PRO, 
        ANDROID_AT5,
        ANDROID_AK1
    }

我想创建一个枚举开关,就像这样:
switch (remoteUnit.getDeviceVersion()) {
            case RemoteUnitType.deviceVersion.ANDROID_AK1 :
            break;  
}

但是我收到了这个错误:
The qualified case label RemoteUnitType.deviceVersion.ANDROID_AK1 must be replaced with the unqualified enum constant 
2个回答

17
您不需要进行资格认证,只需使用枚举的标签:
switch (remoteUnit.getDeviceVersion()) {
            case ANDROID_AK1 :
            break;  
}

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接