Interpret something and run the generated bytecode in Java?

I am writing a toy translator from REPL to Java. I would like to generate bytecode from the language and run it instead of interpreting AST and run it.

Since my Java is a little rusty, is it possible to run running bytecode on the fly on the JVM?

+5
source share
2 answers

You can use java.lang.Classloader.defineClass (), which turns the bytecode into a class object. You can call newInstance () on the resulting class object and leave you.

+5
source

Javassist, snippet, Java - , .

+1

All Articles