google / google/guice

@Singleton not respected if type is parameterized

Open
#317 4 comments 0 reactions 0 assignees View on GitHub
imported Priority-Low
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.