Home >Java >javaTutorial >Does Java Reflection Significantly Impact Application Performance?
Does Java Reflection Affect Performance?
Using reflection to instantiate objects instead of invoking the constructor directly is an expensive operation. As stated in Java's documentation on reflection:
"Because reflection involves types that are dynamically resolved, certain Java virtual machine optimizations cannot be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts and should be avoided in frequently called code in performance-sensitive applications."
A simple test using Sun JRE 6u10 yielded the following results:
Even if the lookup and instantiation are done together, reflection still incurs a performance penalty:
These results highlight that reflection should be avoided in performance-sensitive code.
The above is the detailed content of Does Java Reflection Significantly Impact Application Performance?. For more information, please follow other related articles on the PHP Chinese website!