Brainbox needed -- KeyEvent VK_* constants stable??!
I'm newish to Java and I've found myself totally flummoxed by something in the documentation that I don't see how can physically make sense, besides the fact that if it did it wouldn't be sensible. I'd really appreciate insight from more knowledgeable folks.
My gripe is with the java.awt.event.KeyEvent api. It defines lots of virtual key code constants for use with the getKeyCode() function. This seemed perfect for what I need (binding some key controls for a game emulator, and loading and storing them from a config file).
Then to my total horror, I saw this note in the documentation:
Originally Posted by Sun idiots
This is totally useless for any sort of permanent key binding, which I need to do to store the keys into a file and have them not break in future VMs. So I made THIS monstrosity to define better constants: pastebin.com/f73084f4f (you'll have to copy & paste the link, sorry, but the forum software wouldn't let me type a link with a 0 post count).
Once I'd updated the rest of my code to use it, it worked perfectly. Then, just to check something, I decided to open up the compiled .class file in Notepad. But the VK_* identifiers are nowhere to be found. They've apparently been inlined by the compiler. I got a disassembler and checked again, and yes, the enums are being initialized like this (with fricking ASCII codes, of all the unrelated things to number virtual key constants with):
So what the heck is going on? I'm really agitated now. The docs say the constants can change, but surely this will break all compiled code even if it isn't storing the key codes externally? I've been searching around for other sources, and several books have the same ominous caution as the docs, but they all seem to be based on that original note. Is the note wrong? Is the VM able to update constants in a way I'm not grasping (based on the version number of the compiler??) ?
A = new StableKey("A", 11, 65);
B = new StableKey("B", 12, 66);
C = new StableKey("C", 13, 67);
D = new StableKey("D", 14, 68);
E = new StableKey("E", 15, 69);
By the way, I'm using the ordinary javac that came with the Sun JDK. I've not run the code through any external optimizer.
Please help. :(