RFR: Generate Java enums

David Alayachew davidalayachew at gmail.com
Mon Jul 7 18:48:48 UTC 2025


No, because ordinal returns 0, 1, 2, 3, 4, 5, etc for each subsequent
value. Whereas, it sounds like you need it to return 1, 2, 4, 8, etc. You
could do the transformation yourself, of course.

But if that doesn't work, maybe come at this from the opposite direction?

What, in Java, gives you this OR-like functionality for enums? EnumSet!
Maybe the better answer would be to have some way to return a long or
long[] from an EnumSet to represent the included values?

On Mon, Jul 7, 2025, 2:40 PM Vivek Narang <duke at openjdk.org> wrote:

> On Thu, 3 Jul 2025 09:38:18 GMT, Maurizio Cimadamore <
> mcimadamore at openjdk.org> wrote:
>
> >
> > ```
> > enum Color
> > {
> >     Red,
> >     Green,
> >     Blue,
> > }
> > ```
> >
> > C code can do things like `Red | Blue` -- which are not possible with
> Java enums.
> >
> Hey @mcimadamore please excuse my gap in understanding here, but won't
> this operation be possible in Java by doing: `Color.Red.ordinal() |
> Color.Blue.ordinal()`?
>
> -------------
>
> PR Comment:
> https://git.openjdk.org/jextract/pull/284#issuecomment-3046175531
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jextract-dev/attachments/20250707/87802601/attachment.htm>


More information about the jextract-dev mailing list