21

As far as I can tell, Java has no such equivalent of C#'s Reflection.Emit stuff. Are there any additional libraries for Java that provide similar functionality? What are the differences (to reflection emit)?

2 Answers2

11

The Byte Code Engineering Library (BCEL)

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 4
    Does BCEL allow the emitted bytecode to be run at runtime (as opposed to saving it to a file)? –  Feb 13 '10 at 22:44
  • Can someone please answer this question? – Jay Sullivan Nov 22 '13 at 00:23
  • @JaySullivan Given the age of this you may already know this: you are more likely to get responses on new questions than hoping someone answers a comment on an old question. – vossad01 Feb 03 '17 at 23:56
  • 2
    @vossad01 as far as I know SO, the new question gets closed within few minutes for being a duplicate :-\ – t3chb0t Apr 22 '19 at 08:21
9

Besides Darin's excellent answer (+1), ASM is worth checking out too.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • 2
    After investigating it seems ASM is the best fit for me. I also came across some stuff that compared it favourably with regard to performance. Thanks! –  Feb 16 '10 at 18:15
  • 2
    @PythonPower: since you've investigated ASM, can you tell me if it allow the emitted bytecode to be run at runtime? And/or if BCEL does if you've found out since? – Jay Sullivan Nov 22 '13 at 00:24