Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch on Enum in Java: unqualified enum constant

Tags:

java

enums

I have this enum :

public class RemoteUnitType implements Serializable {

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

and I want to create a switch on Enum, like this

switch (remoteUnit.getDeviceVersion()) {
            case RemoteUnitType.deviceVersion.ANDROID_AK1 :
            break;  
}

But I got this error:

The qualified case label RemoteUnitType.deviceVersion.ANDROID_AK1 must be replaced with the unqualified enum constant 
like image 426
en Lopes Avatar asked Dec 18 '22 04:12

en Lopes


1 Answers

You do not need to qualify, just use the enumeration's label:

switch (remoteUnit.getDeviceVersion()) {
            case ANDROID_AK1 :
            break;  
}
like image 164
pleft Avatar answered Jan 09 '23 16:01

pleft