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

anonymous this refers to super instance instead of enclosing instance

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 1.2.0
    • 1.2.0
    • tools
    • 1.2fcs
    • sparc
    • solaris_2.5.1
    • Not verified



      Name: tb29552 Date: 04/29/98


      the following program prints

       Error at err3 :: Z.this.m = 1 :: expected value 100

      According to the inner class documentation, the
      qualified this syntax should cause references to
      enclosing instances. (Anyway, why have another
      way to refer to the super instance?)

      //Chk.java:
      class Chk {

        Chk(){}

        public static boolean ErrorFlag = false;

        public static boolean chkIntVal(String errStr, String varName, int val, int expectedVal)
          {
             if(val!=expectedVal) {
               ErrorFlag=true;
               System.out.println("Error at " + errStr + " :: " + varName + " = " + val +" :: expected value " + expectedVal);
               return false;
             }
             else
               return true;
          }
      }

      //X.java:
      class X
      {
          int m=101;

        
         class Z
         {
          int m=100;

          void test()
          {
           new Z()
           {
            int m=200;
            void test()
            {
             Chk.chkIntVal("err1","m",m,200);
             super.m = 1;
             Chk.chkIntVal("err2","super.m",super.m,1);
             Chk.chkIntVal("err3","Z.this.m",Z.this.m,100);
             Chk.chkIntVal("err4","X.this.m",X.this.m,101);
            }
           }.test();
          }
       }
      void xtest()
      {
      new Z().test() ;
      }
         
         public static void main(String[] s)
         {
           new X().xtest();
         }
       
       }
      (Review ID: 29251)
      ======================================================================

            wmaddoxsunw William Maddox (Inactive)
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: