Stats

660 Contributors: 22 Monday, July 3, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

Reflection API

Introduction

Reflection is commonly used by programs which require the ability to examine or modify the runtime behavior of applications running in the JVM. Java Reflection API is used for that purpose where it makes it possible to inspect classes, interfaces, fields and methods at runtime, without knowing their names at compile time. And It also makes it possible to instantiate new objects, and to invoke methods using reflection.

Remarks

Performance

Keep in mind that reflection might decrease performance, only use it when your task cannot be completed without reflection.

From the Java tutorial The Reflection API :

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.

Related Examples