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

Do non-static final fields with constant initializers define constants?

    XMLWordPrintable

Details

    • kestrel
    • sparc
    • solaris_2.4

    Description



      Name: vsC45997 Date: 11/20/96


      If I recompile a class containing a final field (not static) with
      the new value to which the field is initialized then I cannot obtain
      this new value by access to the field from the subclass which was
      not recompiled.

      The section "13.4.8 final Fields and Constants" of The JLS contains the following:

      "If a field is a primitive constant, then deleting the keyword final or
      changing its value will not break compatibility with pre-existing
      binaries by causing them not to run, but they will not see any new
      value for the constant unless they are recompiled."

      But the field from my test is not primitive constant because it is
      not static. I guess the new value must be provided. If my suggestion
      is wrong and an assertion analogous the assertion above should be for
      non-primitive constants, it should be written in JLS.


      Lets consider my test on binary compatibility.
      The test consist of two files.

      // FILE: binc01802.java
      package javasoft.sqe.tests.lang.binc018.binc01802;
      import java.io.PrintStream;

      class Super { final char f = 'f'; }

      public class binc01802 extends Super {
        public static void main(String argv[])
        {
          System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
        public static int run(String argv[],PrintStream out) {
          char s = new Super().f;
          out.println(s);
          if ( s == 's' )
            return 0;
          else
            return 2;
        }
      }
          
      // FILE: binc01802a.java
      package javasoft.sqe.tests.lang.binc018.binc01802;
      class Super { final char f = 's'; }
         

      After separate compilation and execution with -verify option we have
      on both 1.0.2 and 1.1 compilers:
      javac -d . binc01802.java
      javac -d . binc01802a.java
      java -verify javasoft.sqe.tests.lang.binc018.binc01802.binc01802
      f

      ======================================================================

      Attachments

        Activity

          People

            jrose John Rose
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: