According to http://www.scribd.com/doc/8128172/Preon-Introduction , Preon can be used to decode bits into an enum representation as such:
// Reads a bit from the buffer, and interprets it as an enum value,
// interpreting the number as its ordinal value.
@BoundNumber(size="2")
Type type;
Now, my question is: if you have an enum such as:
public static enum TestEnum {
VALUE_A, VALUE_B
}
Does 00 always map to VALUE_A, and 01 always to VALUE_B because they are written in that (ascending?) order?
Can I count on this always being the case?
In what ways are enums valued in Java and how does Preon resolve this situation?
Yes they do. The javadoc of the synthetic method
values()
states it. See JLS 8.9.2.and the javadoc for Enum.ordinal() states
So if you do
you will always get
in your case.