Updates:
Status: Fixed
Comment #9 on issue 72 by limpbizkit: Injector does not respect
constructor's private visibility
http://code.google.com/p/google-guice/issues/detail?id=72
The current code is a good balance between following the user's intents and
ease-of-migration. Here's what
we support, in order of preference:
1. A single @Inject constructor.
2. No-args, non-private constructors. Often this is a compiler-generated
constructor.
3. No-args private constructors of private classes. Often this is a
compiler-generated constructor.
If we wanted to tighten the rules further, I think we'd make user code
worse. For example, consider an inner
class that exists solely for testing:
public class Stopwatch {
@Inject
Stopwatch(Ticker ticker) {
...
}
public Stopwatch() {
this(new Ticker());
}
// for testing
static class Ticker {
long now() {
return System.currentTimeMillis();
}
}
}
If we were to forbid say, default package-private constructors, then the
user would need to create a
constructor just for a place to hang the annotation; ie.:
static class Ticker {
@Inject
Ticker() {}
long now() {
return System.currentTimeMillis();
}
}
That's lame, especially since it will impact lots of existing code. (Just
changing our own tests is a large job)
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en
-~----------~----~----~----~------~----~------~--~---