1. Index: Foo.java
  2. ===================================================================
  3. --- Foo.java    (revision 57)
  4. +++ Foo.java    (working copy)
  5. @@ -1,6 +1,10 @@
  6. +    import java.lang.reflect.Constructor;
  7. +    
  8.      class Foo {
  9.  
  10.          public Foo () {}
  11. +        
  12. +        public Foo (FooTest f) {}
  13.  
  14.          public void whichClassAmI () {
  15.              System.out.println(this.getClass());
  16. @@ -14,7 +18,8 @@
  17.              
  18.              try {
  19.                  Class<? extends Foo> c = this.getClass();
  20. -                T r = (T)(c.getConstructor().newInstance());
  21. +                Constructor cst = c.getConstructor(c.getEnclosingClass());
  22. +                T r = (T)(cst.newInstance(c.getEnclosingClass().newInstance()));
  23.                  return r;
  24.              } catch (Exception e) {
  25.                  throw new RuntimeException(e);
  26. Index: FooTest.java
  27. ===================================================================
  28. --- FooTest.java    (revision 57)
  29. +++ FooTest.java    (working copy)
  30. @@ -2,8 +2,15 @@
  31.  
  32.          public static String stuff = "";
  33.  
  34. +
  35. +
  36.          public static void main (String[] args) {
  37. +            FooTest t = new FooTest();
  38. +            t.go();
  39. +        }
  40.  
  41. +        public void go() {
  42. +
  43.              Foo f1 = new Foo();
  44.  
  45.              // instance of anon subclass
  46. @@ -20,8 +27,8 @@
  47.              f1.say();
  48.              f2.say();
  49.              
  50. -            Foo f3 = f1.getAnotherFoo();
  51. -            f3.say();
  52. +            //Foo f3 = f1.getAnotherFoo(); // <-- doesnt work anymore cuz enc-class is null
  53. +            //f3.say();
  54.              
  55.              Foo f4 = f2.getAnotherFoo(); // <-- exception here
  56.          }