views:

114

answers:

1

Can i write bytecode inside a method of a class so that the compiler bypasses that part since it is already compiled. Something similar to writing assembly programs in C language using "asm"...

+2  A: 

I think you mean Java. If that's the case:

Short answer: no.

Long answer: There is nothing like asm { ... } in Java. But you could (not very clever in most situations) write a .class file (or have bytecode in textual representation and then assemble it in Java to a .class file) from Java and dynamically load and execute it.

Johannes Weiß
You said... "(or have bytecode in textual representation and then assemble it in Java to a .class file)"...can you give more inputs on this...
AD
Sure, you store the textual bytecode representation (as `javap -c SomeJavaClass` outputs it) as a `String` in your Java source. While your program is running, you can assemble that code(e.g. with Jasmin (http://jasmin.sourceforge.net/)) which gives you a `.class` file. That class can be loaded dynamically with the class loader. Finally, you can execute anything from that class.
Johannes Weiß