-2

is it mandatory to write a setter function when we use @Inject annotation

  • the documentation of that annotation explains what it can do: https://docs.oracle.com/javaee/7/api/javax/inject/Inject.html – zapl Oct 13 '22 at 20:36

2 Answers2

0

Nope. It is not mandatory. Reflection is used to set the value.

See this and this for more info.

Renis1235
  • 4,116
  • 3
  • 15
  • 27
0

No, we don,t have to write the setter method for @Inject, it is same annotation as the @Autowired.

@Inject is part of a Java technology called CDI that defines a standard for dependency injection similar to Spring. In a Spring application, the two annotations works the same way as Spring has decided to support some JSR-299 annotations in addition to their own.

@Inject can be injected the reference to the implementation of the Provider interface, which allows injecting the deferred references.