Return to site

JAVA Reflection API

· java

Define

Reflection is an API which is used to examine or modify the behavior of methods, classes, interfaces at runtime.
The required classes for reflection are provided under java. lang. reflect package.
Through reflection we can invoke methods at runtime irrespective of the access specifier used with them.

Drawbacks

Reflection should not be used indiscriminately.
If it is possible, it is preferable to avoid using it.

Performance overhead

Reflective operations have slower performance than their non-reflective counterparts
It should be avoided in performance-sensitive applications.

Security restrictions

Reflection requires a runtime permission which may not be present when running under a security manager.

Exposure of internals

Reflection allows code to perform operations that would be illegal in non-reflective code, such as accessing private fields and methods.
It could have unexpected side-effects, which may render code dysfunctional and may destroy portability.
Reflective code breaks abstractions and therefore may change behavior with upgrades of the platform.