How do you bind to generics?

2009-04-14 Thread aemami
Hi, I am trying to accomplish the following: bind(ICache.class).to(Cache.class); and bind(IMyMapper.class).to(NpcMapper.class); This doesn't seem possible in Java, or is it? Keep in mind I'm not a java guy, I'm used to using Ninject (which was patterned after Google Guice) and C#. Thanks --~

Re: How do you bind to generics?

2009-04-14 Thread jordi
that's a java defect or not provided feature. instead use TypeLiteral your code should be something like : TypeLiteral> inpc = new TypeLiteral>() {}; TypeLiteral> npc = new TypeLiteral>() {}; bind(inp

Re: How do you bind to generics?

2009-04-14 Thread Logan Johnson
protip: If you frequently have to bind the same type with different parameters, make yourself a helper method and get that TypeLiteral noise out of your configure() methods. static TypeLiteral> mapper(Class mapped) { return new TypeLiteral>() {}; } void configure() { bind(mapper(Npc.class

Re: How do you bind to generics?

2009-04-14 Thread aemami
Nice, that worked. How do I then go about getting the instance in question? I.e. injector.getInstance( new TypeLiteral>() {}); doesn't work On Apr 14, 2:09 pm, jordi wrote: > that's a java defect or not provided feature. instead use > TypeLiteral

Re: How do you bind to generics?

2009-04-14 Thread aemami
Nevermind I figured it out :) new Key> On Apr 14, 3:03 pm, aemami wrote: > Nice, that worked. > > How do I then go about getting the instance in question? > > I.e. injector.getInstance( new TypeLiteral>() {}); doesn't > work > > On Apr 14, 2:09 pm, jordi wrote: > > > that's a java defect or n