class Foo { public Foo () {} public Foo (FooTest f) {} public void whichClassAmI () { System.out.println(this.getClass()); } public void say () { System.out.println("Foo says: nothing"); } public T getAnotherFoo () { Class c = this.getClass(); Class enc = c.getEnclosingClass(); if (enc == null) { // for the f3 clone which has no enclosing class return (T)new Foo(); } else { // for the f4 clone of the anon subclass instance try { T r = (T)(c.getDeclaredConstructor(enc) .newInstance(enc.newInstance())); return r; } catch (Exception e) { throw new RuntimeException(e); } } } }