adding a method and a variable with BCEL

L

lemonj

Hi there,

I need to add a variable (i.e. value) and a getter (i.e. getValue) to
MyObject.class. The example code in the distribution package showed
only how to modify existing methods. Is there a simple way to do it. Or
may be other byte code injectors?
Thanks a lot,
 
T

Thomas Hawtin

I need to add a variable (i.e. value) and a getter (i.e. getValue) to
MyObject.class. The example code in the distribution package showed
only how to modify existing methods. Is there a simple way to do it. Or
may be other byte code injectors?

IIRC, create FieldGen and MethodGen objects through their constructors,
using the ConstantPoolGen from the ClassGen. When it is all set up, call
getField/getMethod and then addField/addMethod on ClassGen.

ObjectWeb ASM is much simpler.

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top