You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AnonymousWithInner.java 910B

1234567891011121314151617181920212223242526272829303132333435
  1. // anonymous inner classes with inner types
  2. import org.aspectj.testing.Tester;
  3. public class AnonymousWithInner {
  4. public static void main(String[] args) {
  5. new AnonymousWithInner().foo();
  6. // we're getting two 'cause we called toString twice
  7. Tester.checkEvents(new String[] { "x = 37", "x = 37" });
  8. }
  9. int x = 37;
  10. void foo() {
  11. Object inner = new Object() {
  12. class Inner {
  13. void m() {
  14. Tester.event("x = " + x);
  15. }
  16. public String toString() {
  17. m();
  18. return "Inner";
  19. }
  20. }
  21. Object m2() {
  22. return new Inner();
  23. }
  24. }.m2();
  25. inner.toString();
  26. Tester.checkEqual(inner.toString(), "Inner");
  27. }
  28. }