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

"this.value" allowed as case label.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.4
    • tools
    • None
    • generic
    • solaris_2.5.1

      The JLS says that a case label needs to be a ConstantExpression. The yield of ConstantExpression does not include expressions of the form "this.value". Nevertheless, javac compiles the following program without complaint:

      public
      class Case {
          static final int value = 100;

          void method(int i) {
      switch (i) {

      case this.value :
      System.out.println("hi");
      break;

      }

          }
      }

      This error allows some incorrect code to compile.

            tturnidgsunw Todd Turnidge (Inactive)
            tturnidgsunw Todd Turnidge (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: