Is there any tool which provides Java dynamic code generation and that also supports generics?
Javassist for example, is the kind of tool that I need, but it does not support generics.
I wrote a small lib which uses the Java 6 Compiler API, however as far as I know it depends on JDK. Is there a way to specify another compiler? Or to ship with my application only the parts that I need to invoke with the Java Compiler API?
It seems you can manipulate and read generic info with Javaassist. See
http://www.mail-archive.com/jboss-user@lists.jboss.org/msg101222.html
If I recall correctly, it is sufficient to have tools.jar in the classpath in order to use the Java compiler at runtime.
If you are comfortable with writing bytecode then ASM is quite a good library for that kind of thing. That will let you generate a class file on the fly without having to worry about the nitty-gritty of the classfile format. You can then use a classloader to dynamically load it into your application.
Actually, javaassist can handle generics using
SignatureAttribute
.This project has a lot of very good examples. Hop they are helpful.