I need to use switch case
with byte
contants. I have static final
constants declared like follows:
private static final byte[] X_CONST = {2};
private static final byte[] Y_CONST = {3};
Then I want to use switch case like follows :
byte[] x={3};
switch (x[0]){
case X_CONST[0]: ...; break;
case Y_CONST[0]: ...; break;
}
The array may be static final, but the content of the array isn't. So it isn't allowed as the case value of a switch as the value itself could be changed at runtime. You will need to specify private static final byte X_CONST = 2
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With