This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Bug accessing variable in superclass from inner class of subclass.


I haven't seen this in GNATS, so I'll report it once again, as it seems
my post in mid-January was overlooked (or perhaps the problem is simply
difficult to solve). I apologize if this is already known.

This problem does not occur of Super and Inner are not inner classes of
Test.

// When id is a member of Inner's superclass, and Inner2 tries to access
// it, it is munged to 0.

public class Test {
    public static void main(String[] args) {
        Test t = new Test();
    }

    public Test() {
        (new Inner()).doit();
    }

    public class Super {
        public int id = 42;
    }

    public class Inner extends Super {
        public void doit() {
            System.out.println("works here: "+id);
            (new Inner2()).doit();
        }

        public class Inner2 {
            public void doit() {
                System.out.println("but not here: "+id);
            }
        }
    }
}

mjr::mjr$ javac Test.java ; java -cp . Test
works here: 42
but not here: 42
mjr::mjr$ gcj --main=Test -o test Test.java ; ./test
works here: 42
but not here: 0
mjr::mjr$


-- 
Mark Roberts
mjr@statesmean.com



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]