@Inject
我只是在不小心用代替注释方法后才注意到这一点@Override
。Guice 是故意允许这样做还是应该将其视为错误?
public class GuiceExample {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(GuiceManagedResource.class);
}
});
// The following is printed to the console:
//
// constructor
// doSomethingUnexpected
injector.getInstance(GuiceManagedResource.class);
}
static class GuiceManagedResource {
@Inject
GuiceManagedResource() {
System.out.println("constructor");
}
@Inject
void doSomethingUnexpected() {
System.out.println("doSomethingUnexpected");
}
}
}