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

using "super" keyword in an instance variable initializer

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1fcs
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Not verified

      Description



      Name: laC46010 Date: 10/28/96


      The Java Language Specification says:

      [8.3.2.2 Initializers for Instance Variables, p.150]

      "Initialization expressions for instance variables are
      permitted to refer to the current object this (15.7.2) and to
      use the keyword super (15.10.2, 15.11)."

      [15.10.2 Accessing Superclass Members using super, p.322]

      "The special form using the keyword super is valid only in an
      instance method or constructor, or in the initializer of an
      instance variable of a class; these are exactly the same
      situations in which the keyword this may be used (15.7.2)."

      However compiler (both 1.0.2 and 1.1) treats "super" as undefined variable
      in an instance variable initializer and reports an error:

      > /export/ld32/jdk_1.0.2/bin/javac clss10203.java
      clss10203.java:10: Undefined variable: super
        int k = super.j;
                ^
      1 error

      > /export/ld32/jdk_1.1/bin/javac clss10203.java
      clss10203.java:10: Undefined variable: super
        int k = super.j;
                ^
      clss10203.java:10: Undefined variable: super
        int k = super.j;
                ^
      2 errors

      Besides 1.1 version reports the message twice
      but it's probably defect of the September version.

      ------------------clss10203.java---------------------
      class clss10203_a {
        int j = 1;
      }

      public class clss10203 extends clss10203_a {
        void f() {
         int n = super.j;
         super.j = 1;
        }
        int k = super.j;
      }
      -----------------------------------------------------

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

        Attachments

          Activity

            People

            Assignee:
            jrose John Rose
            Reporter:
            leosunw Leo Leo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: