Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8234552

KeyEvent doc has irritating warning about changing constants

XMLWordPrintable

    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      The documentation for java.awt.event.KeyEvent contains the following warning:
      >WARNING: Aside from those keys that are defined by the Java language (VK_ENTER, VK_BACK_SPACE, and VK_TAB), do not rely on the values of the VK_ constants.

      This is rather irritating because when compiling code which contains compile-time constants (such as these VK_ constants) they are replaced with their value. So if these VK_ constants were changed, it would break backwards compability.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the following code and decompile the class file.


      ---------- BEGIN SOURCE ----------
      import java.awt.event.KeyAdapter;
      import java.awt.event.KeyEvent;
      import java.awt.event.KeyListener;

      class KeyEventTest extends KeyAdapter {
          public void keyPressed(KeyEvent e) {
              if (e.getKeyCode() == KeyEvent.VK_A) {
                  System.out.println("Pressed A");
              }
          }
      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: