7.2. Why Generate Code with Java?

Since the principles of generative programming apply to other languages as well, why use Java? One could argue that Java is not particularly well suited to code generation. After all, C++ has built-in support for code generation with macros and templates. Scripting languages like Perl are very good with string operations and might be better suited for writing generators. Despite these valid objections, Java is particularly suited to GP for five reasons:

  1. High quality type information acts as a valuable implicit specification document.

  2. Flexible class loading supports any combination of binding times and binding modes.

  3. Java source files are simple to read and generate.

  4. Java bytecode files are simple to read and generate. ...

Get Component Development for the Java™ Platform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.