google-code-export / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
2 stars 1 forks source link

Honor type parameters #186

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Example:

@Singleton
class Foo<T> {
}

Original issue reported on code.google.com by crazybob...@gmail.com on 12 Mar 2008 at 9:13

GoogleCodeExporter commented 9 years ago
I've committed a test. The interesting problem with this change is that a lot 
of our testcases use List.class and 
ArrayList.class, which we'll need to fix!

Original comment by limpbizkit on 9 Jun 2008 at 6:27

GoogleCodeExporter commented 9 years ago
I have a better solution. We shall honor parameterized types and use them when 
doing injections.  For 
instance, suppose we have this:
  class Foo<T> {
    Set<T> tees;
  }

  class FooModule extends AbstractModule {
    public void configure() {
      bind(new TypeLiteral<Set<String>>() {}).toInstance(ImmutableSet.of("A", "B", "C"));
      bind(new TypeLiteral<Foo<String>>() {});
    }
  }

Anyone asking to inject a Foo<String> will get that, with the Strings set 
injected. 

Consequences:
 - We won't try to inject a raw Foo when a Foo<String> is requested. 
 - It'll be possible to have bindings for both Foo<String> and Foo<Integer> and these will be completely 
independent.

Original comment by limpbizkit on 10 Aug 2008 at 5:23

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 2 Nov 2008 at 8:31

GoogleCodeExporter commented 9 years ago
r660 implements this. We still need to optimize the TypeResolver code.

http://code.google.com/p/google-guice/source/detail?r=660

Original comment by limpbizkit on 4 Nov 2008 at 6:03

GoogleCodeExporter commented 9 years ago
Optimized, and complete. Hooray.
  http://code.google.com/p/google-guice/source/detail?r=663

Original comment by limpbizkit on 14 Nov 2008 at 8:49

GoogleCodeExporter commented 9 years ago
Note that now you should remove or revise BinderTest.testBindDisallowedTypes

Original comment by d...@google.com on 17 Nov 2008 at 5:47