BTW. storing & retrieving of Enums through ordinals will fail if one
changes the order of the fields (or prepends new fields).
enum Numbers {
ONE, // ordinal=0
TWO, // ordinal=1
}
IoBuffer buffer;
buffer.putEnum(Numbers.ONE);
buffer.flip();
Now I'm changing something in my Numbers Enum
enum Number {
ZERO, // ordinal=0
ONE, // ordinal=1
TWO, // ordinal=2
}
Number num = buffer.getEnum(Number.class);
System.out.println(num); // Expected ONE but is ZERO
James
On Wed, Feb 20, 2008 at 6:20 PM, Emmanuel Lecharny <[EMAIL PROTECTED]> wrote:
>
> Tuure Laurinolli wrote:
> > Stuart Scott wrote:
> >> I noticed that the various getEnum/putEnum methods in IoBuffer use the
> >> signed values of the various data types. As Enums cannot have negative
> >> ordinals would it not be more useful to use the unsigned version of the
> >> data type?
> >
> > What unsigned version would that be? There is only one unsigned
> > integral data type in Java, and that is char (JLS 4.2.1). Also,
> > handling shorter integral types in Java is tiresome, since they get
> > cast to int as soon as you apply some operator to them (JLS 15.x).
> Also you can store negative value in an enum, assuming you affect this
> value instead of using the default incremental value.
> >
> >
>
>
> --
> --
> cordialement, regards,
> Emmanuel Lécharny
> www.iktek.com
> directory.apache.org
>
>
>