I'm using javassist API to create a method :
CtMethod newmethod = CtNewMethod.make("public boolean preRemove(){return size==getObjectSize();}",ctclass);
this method calls an other method getObjectSize() that exist in that class
in this case I get attempted duplicate class definition for name
with LinkageError
provoked by this instruction Class clazz = ctclass.toClass();
So, I tried to create my own classLoader CustomClassLoader loader = new CustomClassLoader();
and then I didn't get the new method when I listed the methods of the class
ClassPool pool = ClassPool.getDefault();
CtClass ctclass = pool.get("javaExp.SinglyLinkedList");
ctclass.stopPruning(true);
CtMethod newmethod = CtNewMethod.make("public boolean preRemove(){return size==getObjectSize();}",ctclass);
ctclass.addMethod(newmethod);
ctclass.writeFile();
Class<?> clazz =loader.loadClass("javaExp.SinglyLinkedList");
Method []m= clazz.getDeclaredMethods();
for(int i=0;i<m.length;i++){
System.out.println(m[i].getName());
}