summaryrefslogtreecommitdiffstats
path: root/tests/pureJava/AnonymousWithInner.java
blob: 85d236cdedb26bfb9d8b0d526efe712695c9d81a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// anonymous inner classes with inner types

import org.aspectj.testing.Tester;

public class AnonymousWithInner {

    public static void main(String[] args) {
        new AnonymousWithInner().foo();
        // we're getting two 'cause we called toString twice
        Tester.checkEvents(new String[] { "x = 37", "x = 37" });
    }

    int x = 37;

    void foo() {
        Object inner = new Object() {
                class Inner {
                    void m() {
                        Tester.event("x = " + x); 
                    }
                    public String toString() {
                        m();
                        return "Inner";
                    }
                }
                Object m2() {
                    return new Inner();
                }
            }.m2();
        inner.toString();

        Tester.checkEqual(inner.toString(), "Inner");
    }
}