Skip to content
Sharp

Dependency Injection · interview question

How does using 'final' with constructor-injected dependencies in Spring Boot help during development?

Multiple choiceMediumchapter-9-curatedpremiumdependency-injectionconstructor-vs-field-injection
Choose one answer
Answer and explanation

Correct answer

A. It prevents accidental reassignment of dependencies

Why

Marking dependencies as 'final' in constructor injection prevents them from being reassigned after the object is constructed, reducing the risk of accidental reassignments and thus ensuring safer and more predictable code.

Test yourself on Dependency Injection

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

Start free test
All Dependency Injection questions →