private static Class<?> generateClassHierarchy(List<List<Class<?>>> classes) {
    TestClassLoader loader = new TestClassLoader();
  
    String superClassDesc = "java/lang/Object";
    int classIndex = 0;
    
    for (List<Class<?>> fields : classes) {
      String classDesc = "A" + classIndex++;
      ClassWriter cw = new ClassWriter(COMPUTE_MAXS | COMPUTE_FRAMES);
      cw.visit(V1_6, ACC_PUBLIC, classDesc, null, superClassDesc, null);
      MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, superClassDesc, "<init>", "()V");
      mv.visitInsn(RETURN);
      mv.visitMaxs(1, 1);
      mv.visitEnd();

      int fieldIndex = 0;
      for (Class<?> field : fields) {
        cw.visitField(ACC_PUBLIC, "a" + fieldIndex++, Type.getDescriptor(field), null, null);
      }
      cw.visitEnd();
      loader.defineClass(classDesc, cw.toByteArray());
      superClassDesc = classDesc;
    }
    
    try {
      return loader.loadClass("A" + (classIndex - 1));
    } catch (ClassNotFoundException e) {
      throw new AssertionError(e);
    } catch (NoClassDefFoundError e) {
      throw new AssertionError(e);
    }
  }