☕ Java Intermediate

What is Java Reflection?

Why Interviewers Ask This

Mid-level Java roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.

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.

Common Mistake

Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Java experience.