We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i want to create a new class by template class and change template class'non-static method to static method
import javassist.ClassPool; import javassist.CtClass; import javassist.Modifier; public class Template { public void templateMethod(Object arg) { //do something } public static void main(String[] args) throws Exception { ClassPool pool = ClassPool.getDefault(); CtClass template = pool.get("Template"); CtClass newClass = pool.makeClass(template.getClassFile()); newClass.setName("FinalClass"); newClass.getDeclaredMethod("templateMethod", new CtClass[]{pool.get(Object.class.getName())}).setModifiers(Modifier.PUBLIC | Modifier.STATIC); Class result = newClass.toClass(sun.misc.Launcher.getLauncher().getClassLoader()); } }
but finall will throw error:
Type top (current frame, locals[0]) is not assignable to reference type
The text was updated successfully, but these errors were encountered:
Before the fix maybe you can use:
class MyClassLoader extends ClassLoader { ... }
public class Template { . . . byte[] b = newClass.toBytecode() ClassLoader cl = new MyClassLoader.defineClass(newClass.getName(), b, 0, b.length) }
Sorry, something went wrong.
No branches or pull requests
i want to create a new class by template class and change template class'non-static method to static method
but finall will throw error:
Type top (current frame, locals[0]) is not assignable to reference type
The text was updated successfully, but these errors were encountered: