Other answers indicate a problem in your code. As a workaround, you can create an enumeration to use the switch statement, for example:
public enum MY_ENUM { X_CONST((byte)2), Y_CONST((byte)3); private final byte value; private MY_ENUM(byte value) { this.value = value; } public byte getValue() { return value; } public static MY_ENUM valueOf(byte b) { MY_ENUM[] values = MY_ENUM.values(); for (int i = 0; i < values.length; i++) { if (values[i].getValue() == b) { return values[i]; } } throw new IllegalArgumentException("Invalid input byte"); } }
...
public static void main(String[] args) { byte[] x={3}; switch (MY_ENUM.valueOf(x[0])) { case X_CONST: ...; break; case Y_CONST: ...; break; } }
source share