Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What kind of runtime optimizations are lost if we use reflection

In this discussion about the performance overhead of using reflection, it is stated:

Use of reflection can cause some runtime optimizations to be lost. For example, the following code is highly likely be optimized by a Java virtual machine:

int x = 1;
x = 2;
x = 3;

Equivalent code using Field.set*() may not.

Without reflection, what kind of runtime optimizations would be done by JVM?

like image 206
Victor Avatar asked Oct 08 '13 16:10

Victor


1 Answers

In this case the code can be discarded as it doesn't appear to do anything.

If you used reflection I suspect it would still do something although you can't access a local variable using reflection.

like image 78
Peter Lawrey Avatar answered Oct 28 '22 23:10

Peter Lawrey