File: JavaxInjectOnAbstractMethod.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (14 lines) | stat: -rw-r--r-- 779 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
The [`Inject`] annotation cannot be applied to abstract methods, per the JSR-330
spec, since injectors will only inject those methods if the concrete implementer
of the abstract method has the [`Inject`] annotation as well. See
[OverridesJavaxInjectableMethod] for more examples of this interaction.

Currently, default methods in interfaces are not injected if they have
[`Inject`] for similar reasons, although future updates to dependency injection
frameworks may allow this, since the default methods are not abstract.

See the [Guice wiki] page on JSR-330 for more.

[`Inject`]: http://javax-inject.github.io/javax-inject/api/javax/inject/Inject.html
[OverridesJavaxInjectableMethod]: OverridesJavaxInjectableMethod
[Guice wiki]: https://github.com/google/guice/wiki/JSR330