Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Serious answer.</p> <p>I'd auto-generate Java code and use the Java compiler to generate the class file. This look a lot easier then battling BCEL. At least because it's easier to code an algorithm in a 'higher' language than in Java Byte Code.</p> <p>Any other programming language that produces byte code will do aswell, but i guess Java is one of the easiest approaches.</p> <p>And coming to your questions,</p> <p>(1) Yes, some metadata is pretty static. Wikipedia has a nice overview of the <a href="http://en.wikipedia.org/wiki/Class_(file_format)" rel="nofollow noreferrer">class file format</a></p> <p>(2) Yes, the classfile is 'binary'. There is no <em>alphanumerical</em> language (like assembler) for java bytecode (at least I haven't heard of any such tool, javap can print bytecode readable but there's no way back)</p> <p><strong>Edit</strong></p> <p>Still hard to guess, what you really want to do, but just in case, you want to write a classfile around an arithmetic expression that can evaluate that arithmetic expression in a java virtual machine, then you really could start with creating a template class file.</p> <p>In that case I'd code this 'evaluator' in Java and test it until it evaluates all valid inputs. I'd use a private field to hold the expression, initialised with a dummy expression.</p> <p>The classfile of my Java coded evaluator would be a perfect template for the 'dynamic' class generation - I just had to find out how to 'replace' the dummy expression with a real one, recreate valid classfile (you may have to adjust some pointers because of different string lengths) and it should work.</p> <p>Even if this guess is totally wrong, it may serve as case study and may help you on your way :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload