java - How do I remove the body of a method or constructor with javassist? -
i need remove body of constructors , methods w/ void return type using javassist library. following works.
ctclass.getconstructors()[0].setbody("int = 0"); but doesn't
ctclass.getconstructors()[0].setbody(""); instead exception
compile error: syntax near "" when try
ctclass.getconstructors()[0].setbody(null); i get
compiler error: no such constructor i same error when trying empty method w/ void return type. looking through google , documentation, can't figure out how empty out body without inserting kind of code , don't want add arbitrary code no reason.
javassist replaces method body valid block body of method. non-statement not valid block. can instead set { } method body block. alternatively, make implicit return; statement explicit.
for constructor, required invoke super costructor or auxiliary constructor first. empty block not valid.