code: public static Object createDeepInstance(final Stack<Class<?>> classHierarchy) throws Throwable {
          if (classHierarchy == null || classHierarchy.isEmpty())
              throw new IllegalArgumentException("Stack must not be null or empty!");
  
          try {
              // Top level class has empty constructor
              Class<?> outerClass = classHierarchy.pop();
              Object test = outerClass.newInstance();
  
              // Inner class constructors require the enclosing instance
              while (!classHierarchy.empty()) {
                  final Class<?> innerClass = classHierarchy.pop();
                  final Constructor<?> innerConstructor = innerClass.getConstructor(outerClass);
                  test = innerConstructor.newInstance(test);
                  outerClass = innerClass;
              }
              return test;
          } catch (final InvocationTargetException e) {
              throw ((InvocationTargetException) e).getTargetException();
          }
      }
docs: Returns an instance of the {@link Class}, represented by the given class hierarchy.
  
  @param classHierarchy the hierarchy representing a deep class
  @return the newly created instance
  @throws Throwable if errors occurred during construction of the instance