I have the following weird requirement.
I am given:
toString
and obtains an array of strings. To this array, the method applies a function foo
. The function foo
takes as input a String []
type and outputs String
. The methods return what foo
returns. foo
's code is given inside a Java object and is to be accessed as a black-box.The info in 1. and 2. can be in a text or XML file. For this purpose, we can consider it to be available inside a Java object in whatever way we choose.
The task is to create a .class
file (i.e., bytecode) that implements those methods and can be run on the JVM.
I think this assembler library would be one way to do it. Can anyone suggest an easier way?
[EDIT:] I can think of one other way: first generate the .java
file and then compile it to get the .class
file.
[The context:] I have to do this for several hundreds of methods. I want the shortcut so I can automate my job rather than manually write the code.
You could generate the required program code in Java syntax and turn it into a class file using the compiler. It's possible to instantiate javac
at run time and pass it a byte array instead of the location of the source file. This is probably the easiest for other programmers to maintain.
If you want to generate byte code directly, asm is the library most commonly used.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments