Java / Micronaut Interview questions
What is the purpose of the @Inject annotation in Micronaut?
@Inject marks a constructor, field, or setter method as a point where Micronaut should supply a dependency from the ApplicationContext rather than the class constructing it itself.
On a constructor, it's actually optional when there's only one constructor - Micronaut treats a single constructor as implicitly injectable - but it's still commonly added for clarity or required when multiple constructors exist and one needs to be chosen. On fields or setters, @Inject is required to signal that injection should happen there.
Under the hood, the compile-time processor records every @Inject point in the bean's BeanDefinition, so the container knows exactly what to resolve and pass in when constructing the instance, with no reflective field scanning involved.
More Related questions...