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ß
2010-03-03 14:55:45
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
2010-03-03 15:01:49
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ß
2010-03-04 11:07:45