Sunday, October 30, 2005

Efficiency (or lack of) in Java reflection: glad we have it anyway

It is good that the java.lang.reflect package exists. This interesting read (a PDF file on java.sun.com) shows a great example of using a decorator/proxy/delegation pattern for implementing a logging property across multiple classes. Neat stuff and I like this better than, for example, using Aspect Oriented Programming (AOP) to get the same effect: add logging without touching original POJO classes.

However, Java reflection is not very efficient and I have seen at least one very large Java application that has poor performance because it performs lots of reflection. Other languages like Ruby have better support. Common Lisp Object System (CLOS) with support for things like before/after methods, class slot introspection, etc. also is very effective for applications requiring more flexibility than Java.

No comments: