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

can a final variable be the operand of ++? --? +=?

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7, 8
    • 1.4.0
    • specification
    • Verified

      The last paragraph in JLS 15.14.1 suggests that this is illegal

      final int i;
      i++;

      but it is not clear if that is a normative rule or intended to be
      a consequence of other rules. For example, one could imagine the
      rule not applying in the following code, where i is both DA and DU:

      final int i;
      if (false) i++;

      Similarly, section 15.26 (last paragraph) has similar language, but
      it seems to make some allowance for blank finals. Again, it is not
      clear if this rule is intended to be normative.

      We should have a consistent story for these two paragraphs, and we
      should decide and make clear if this restriction is normative or a
      consequence of rules elsewhere. Whichever way this is resolved,
      the compiler will need to be checked for compliance.

            abuckley Alex Buckley
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: