Skip to content
Sharp

Java Annotations · interview question

Why might a Java framework require annotations with RetentionPolicy.RUNTIME when implementing a feature such as dependency injection?

Multiple choiceHardchapter-16-curatedpremiumjava-annotationsretention-policies
Choose one answer
Answer and explanation

Correct answer

D. To inspect and inject dependencies at runtime using reflection.

Why

Frameworks use RetentionPolicy.RUNTIME to inspect classes, methods, or fields via reflection and inject dependencies dynamically. This allows the framework to modify behavior based on annotations present at runtime.

Test yourself on Java Annotations

A free test with instant, explained results. No account needed.

Start free test
All Java Annotations questions →