@SuppressWarnings("unchecked") public static <T> Class<T> getModifiedClass(Class<T> clazz, Annotation[] add) throws javassist.NotFoundException, CannotCompileException, InvocationTargetException, IllegalAccessException { ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.get(clazz.getCanonicalName()); for (CtMethod method : cc.getDeclaredMethods()) { ClassFile ccFile = cc.getClassFile(); ConstPool constpool = ccFile.getConstPool(); AnnotationsAttribute attr; attr = filterExistingAnnotations(add, method); addNewAnnotations(add, method, constpool, pool, attr); } cc.setName(cc.getName() + "$ClassModifier$" + COUNTER.increment()); cc.setSuperclass(pool.get(clazz.getCanonicalName())); return cc.toClass(); }