Hi
I try to modify a class 'myclass'
witch imports java.util.*.
If the 'update'-code contains a creation
of a new Object instance
like
ArrayList() al = new ArrayList()
without package-qualification a
javassist.CannotCompileException: no such class: ArrayList
is thrown.
java.util.ArrayList al = new java.util.ArrayList()
works fine.
Thanks for hints & suggestions !
-------------------------------------------------
code example:
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.getAndRename("myclass","myclass_cpy");
// modify validate(...) method
CtMethod meth = cc.getDeclaredMethod("validate");
meth.insertAfter("{ ArrayList al = new ArrayList }"); // --> creates CannotCompileException although java.util.* exists as import in "myclass"
meth.insertAfter("{ java.util.ArrayList al = new java.util.ArrayList }"); // --> works fine
// write Class and create Instance
Class rtc = cc.toClass();
You must always use fully-qualified names.
It's a specification. The compiler cannot expect
what packages you want to import.