@Singleton not respected if type is parameterized
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 1.7k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
_From [NikolayMetchev](https://code.google.com/u/112554531054101551599/) on January 25, 2009 07:43:48_
In the unit test below I have tagged the Injected class with `@`Singleton yet
Guice creates 2 instance of it. This only breaks because of the generic
parameter. If you remove <T> from the code below the unit test passes.
----------------------------------------------
public class TestSingleton {
`@`ImplementedBy(Injected.class) public interface In<T> {}
`@`Singleton public static class Injected<T> implements In<T>{}
public static class InjectSameThingTwice{
`@`Inject public InjectSameThingTwice(In<String> in,
Injected<String> in2){
if (in != in2){
throw new RuntimeException("not the same
instance");
}
}
}
`@`Test public void testGuice() throws Exception {
Guice.createInjector().getInstance(InjectSameThingTwice.class);
}
}
_Original issue: http://code.google.com/p/google-guice/issues/detail?id=317_
Contributor guide
Assessment
This issue has not been assessed yet.