Specializer extends ClassLoader { public <T, U extends T> T specialize(Class<T> parent, U t) throws SpecializationException { try (Logger l = new Logger("ROOT specialize(" + parent.getSimpleName() + " " + t + ")")) { ClassDescriptor specializedClass = specializeClass(t.getClass(), t); return parent.cast(specializeInstance(specializedClass, t)); } }  T specialize(Class<T> parent, U t);  }
@Test public void test() throws Exception { InnerNodeFixture innerNodeFixture = new InnerNodeFixture(new InnerNodeFixture(new LeafFixture("a"), "+" , new LeafFixture("b")), "*", new LeafFixture("c")); System.out.println(innerNodeFixture + "(d):\n" + innerNodeFixture.foo("d")); Specializer specializer = new Specializer(); InterfaceFixture specialized = specializer.specialize(InterfaceFixture.class, innerNodeFixture); System.out.println(specialized + "(e):\n" + specialized.foo("e")); }