1

I am going through Java reflection drawbacks and came across below statement from Java docs:

Performance Overhead

Because reflection involves types that are dynamically resolved, certain Java virtual machine optimizations can not be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts, and should be avoided in sections of code which are called frequently in performance-sensitive applications.

Please help me in understanding this. What it means that reflection involves types that are dynamically resolved? What are the optimizations provided by JVM in general?

3
  • What does the second question mean? Commented Mar 2, 2014 at 19:23
  • 2
    stackoverflow.com/a/547847/829571 Commented Mar 2, 2014 at 19:24
  • this is a long story of programming languages implementation - compilation, code optimization, interpretation, static and dynamic types... learn all that first, and the answer become obvious. Commented Mar 2, 2014 at 19:27

1 Answer 1

2

As you can easily understand the JVM when starts your programs does a lot of improvements to improve the performance of your code (which is a great thing!) but when we are talking about reflection we are talking about a thing which changes in runtime (i could say it's nondeterministic.. the JVM cannot know what it will be until it execute it) so it cannot be improved by JVM because it behaviour could be different in some cases during runtime.

As i always say in this kind of question: here you could found answer of people who know very very good how reflection works.. search around too.

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

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.