title: How to generate bytecode and save to .class file?
body: <p>I have the following weird requirement.</p>
  
  <p>I am given: </p>
  
  <ol>
  <li>A list of some method names.</li>
  <li>Names and types of parameters of the above methods.</li>
  <li>The functionality of the above methods. This is as follows:
  For each parameter, the method converts it to string using <code>toString</code> and obtains an array of strings. To this array, the method applies a function <code>foo</code>. The function <code>foo</code> takes as input a <code>String []</code> type and outputs <code>String</code>. The methods return what <code>foo</code> returns.
  <code>foo</code>'s code is given inside a Java object and is to be accessed as a black-box. </li>
  </ol>
  
  <p>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. </p>
  
  <p>The task is to create a <code>.class</code> file (i.e., bytecode) that implements those methods and can be run on the JVM. </p>
  
  <p>I think <a href="http://asm.ow2.org/" rel="noreferrer">this assembler library</a> would be one way to do it. Can anyone suggest an easier way? </p>
  
  <p>[EDIT:] I can think of one other way: first generate the <code>.java</code> file and then compile it to get the <code>.class</code> file. </p>
  
  <p>[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. </p>