Avoid modifying fields that are already annotated with @Inject
inside an @Inject
annotated constructor.
Here, thing
is marked as injected. However, Example
's constructor is also marked with @Inject
. This is redundant and could cause issues when initializing thing
through both constructor and field injection.
class Example {
@Inject
String thing;
@Inject
public Example(String s) {
thing = s; // thing is already supposed to be injected!
}
}
Only assign fields that are not marked as @Inject
in the constructor.
class Example {
@Inject
String thang;
String thing;
@Inject
public Example(String s) {
thing = s;
}
}