Allow enum
to be used for native constants
#1930
Labels
kind: enhancement ✨
A new feature or use case
enum
to be used for native constants
#1930
It should be possible to use an
enum
to represent some native constants. The driving use case iserrno
. Sinceerrno
values are integers, one naively expects to be able to use them withswitch
; however, this is disallowed in practice because the values are non-constant as far as Java is concerned. Note that the newerswitch
statements in Java 21 and later might allow this though.The constants should be probed lazily as they are today.
Example:
And then:
Internally we could intercept calls to e.g.
java.lang.runtime.SwitchBootstraps#enumSwitch
and replace them with constant integer switches through a small number of transformations.The text was updated successfully, but these errors were encountered: