JavaCompiler from JDK 1.6: how to write class bytes directly to byte[] array?

后端 未结 3 348
灰色年华
灰色年华 2021-01-02 15:52

So I recently learned of the new JavaCompiler API available in JDK 1.6. This makes it very simple to compile a String to a .class file directly fr

3条回答
  •  被撕碎了的回忆
    2021-01-02 16:53

    The reason that there is no standard API to write bytecodes to a byte array is that compiling a single Java source file may result in multiple bytecode files. For example, any source file with nested / inner / anonymous classes will result in multiple bytecode files.

    If you roll your own JavaFileManager, you will need to deal with this situation.

提交回复
热议问题