Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is BCEL == monkeypatching for java?

a colleague pointed me the other day to BCEL which , as best I can tell from his explanation and a quick read, a way to modify at run time the byte code. My first thought was that it sounded dangerous, and my second thought was that it sounded cool. Then I gave it some more thought and I recalled the codinghorror post on monkey-patching and realized that this was basically the same thing. Has anyone ever used BCEL for anything practical? Am I right that this is basically run time monkey patching, or am I missing something?

like image 927
shsteimer Avatar asked Sep 23 '26 13:09

shsteimer


2 Answers

From BCEL's FAQ:

Q: Can I create or modify classes dynamically with BCEL?

A: BCEL contains useful classes in the util package, namely ClassLoader and JavaWrapper.Take a look at the ProxyCreator example.

But monkeypatching is... uhm... controversial, and you probably shouldn't use it if your language doesn't support it.

If you have a good use case for it, may I suggest embbededing Jython?

like image 77
morais Avatar answered Sep 25 '26 03:09

morais


It's a bit more low-level than classic monkey patching, and from what I read, the classes already loaded into the VM are not updated. It only supports saving it to class files again, not modifying run time classes.

like image 39
wvdschel Avatar answered Sep 25 '26 01:09

wvdschel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!