1Z0-900 · Question #52
Which two elements CANNOT be injected by using an @Inject annotation? (Choose two.)
A (static fields) and B (instance fields declared final) cannot be injected using @Inject. Static fields belong to the class rather than an instance - CDI manages instances, so it has no meaningful target for static injection. Final fields must be initialized at declaration or…
Question
Which two elements CANNOT be injected by using an @Inject annotation? (Choose two.)
Options
- Astatic fields
- Binstance fields declared final
- Cconcrete methods
- Dabstract methods
Explanation
A (static fields) and B (instance fields declared final) cannot be injected using @Inject.
Static fields belong to the class rather than an instance - CDI manages instances, so it has no meaningful target for static injection. Final fields must be initialized at declaration or in a constructor, and since field injection occurs after construction, the container has no window to assign them without violating the final contract.
C (concrete methods) is a valid injection point - method injection is fully supported by CDI; the container calls the annotated method and supplies its parameters. D (abstract methods) is also invalid (no method body to call), but it's the less-tested restriction; the two canonical field-level rules are the primary exam targets.
Memory tip: Think "SFi" - Static and Final fields break injection. Static lacks an instance, Final locks out late assignment.
Topics
Community Discussion
No community discussion yet for this question.