If you want to do more than dynamically use an existing method, you may need to compile your String into bytecode. An easy way to do this is to include the Eclipse / JDT compiler cube in your class path, and then you can use it to compile your String into a class, which you can then load.
This type of dynamic code generation and execution is used to convert JSP files to servlets and is used in other packages, such as JasperReports, to convert the report specification to a class, which is then called.
Remember that as with SQL, you must be careful to prevent code entry security issues if any of the String contains user-specified data.
jbindel
source share