Why are annotation annotations holding RUNTIME in dagger 2?

Dagger 2 has a compile time check, so why does the annotation for scope have RUNTIME hold? Why are they needed at runtime?

+5
source share
1 answer

Although I don’t know for sure, I would suggest that Scopes necessarily has runtime retention, because JSR 330 @Scope requires areas to save runtime. Both Dagger 1 and Dagger 2 advertise JSR-330 compatibility, and (as David mentioned in the comments) there are many runtime dependency injection solutions that would absolutely require runtime -declared area annotations.

For a dagger, in particular, I cannot imagine why they would actually be read at runtime, although I believe that some external libraries may use annotation.

Edit Comments: This is not a problem, outdated or otherwise: many DI systems are configured at runtime and require annotation. The dagger is notable for not doing this, but the specification was not written in such a way that holding the execution time was optional. This frees application developers instead of Dagger with a different JSR330 framework, such as Guice or Spring, and frees library developers to make DI-compatible tools or agnostic frameworks, regardless of whether they are configured at compile time or run-time settings. This clarity of specification (i.e., without implementation options) and flexibility (compilation time or runtime) are apparently worth the cost of unnecessarily preserving the annotation and the cost of training.

+4
source

Source: https://habr.com/ru/post/1246147/


All Articles