I\'ve always avoided Java reflection soley based on its reputation for slowness. I reached a point in the design of my current project where being able to use it would make
Reflection is slow for a few obvious reasons:
JIT as wellExceptions wrapped in InvocationTargetExceptions and re-thrown etc.Just because something is 100x slower does not mean it is too slow for you assuming that reflection is the "right way" for you to design your program. For example, I imagine that IDEs make heavy use of reflection and my IDE is mostly OK from a performance perspective.
After all, the overhead of reflection is likely to pale into insignificance when compared with, say, parsing XML or accessing a database!
Another point to remember is that micro-benchmarks are a notoriously flawed mechanism for determining how fast something is in practice. As well as Tim Bender's remarks, the JVM takes time to "warm up", the JIT can re-optimize code hotspots on-the-fly etc.