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.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -