☕ Java Intermediate

What is Java Reflection?

Answer

Reflection is the ability of a program to examine and modify its own structure and behavior at runtime. Through the java.lang.reflect package, you can inspect classes (Class.forName("com.example.MyClass")), list fields and methods, invoke methods dynamically, and even access private members. Reflection is used by frameworks like Spring (dependency injection, annotation processing), Hibernate (ORM mapping), and JUnit (test discovery). It bypasses compile-time type checking, which makes it powerful but risky — improper use leads to security vulnerabilities and performance overhead. Reflection is generally a tool for framework authors, not application code.