1

I've an array of beans and use reflection to retrieve the values within them through their getter methods. All the beans are of the same type, so instead of using reflection for every object, is there any way of generating code(or object) which will have the calls and I can regenerate this object for a different type of bean? I've heard of something like this in Lisp macros, is it possible in Java?

3 Answers 3

1

You could take a look at JAXP (http://download.oracle.com/javase/tutorial/jaxp/index.html) where you can generate beans from xml definitions. For heavy reflection work I find BeanUtils (http://commons.apache.org/beanutils/) helpful.

Sign up to request clarification or add additional context in comments.

Comments

1

Generics may help you in reducing code repetition before you compile and release the class.

You can also compile and deploy class at run-time, see How can I compile and deploy a java class at runtime?

Comments

0

Yes, You can use Velocity (and other tools) to generate the code. However unless performance is critical, it 10x simpler to use reflection.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.