Reflection code destroys the abstractness of Java program structure, so when the program running platform changes, because the abstract logical structure can not be recognized, the effect of code will be different from before.ġ.
Reflection allows code to perform operations that are usually not allowed, so using reflection can lead to unexpected consequences. If a program requires security, it is best not to use reflection. Using reflection usually requires that the program run without security constraints. If it's a less run part of the program, performance won't be a problem.
#Java reflection load class how to#
Moreover, how to use reflection determines the performance. We should avoid using reflection in high performance programs or frequently executed code. Therefore, the efficiency of reflection operation is much lower than that of normal operation. Java reflection mechanism contains some dynamic types, so Java virtual machine cannot optimize these dynamic codes. When it can be completed without reflection, try not to use it. The function of reflection mechanism is very powerful, but it can't be abused.