2

I found other related questions, but none so straightforward:

How can I bind the following generic parameter using Guice?

class A<T> { T a; @Inject A(T a) { this.a=a; } } 

1 Answer 1

3
public class TestGenericBinding { static class A<T> { T a; @Inject A(T a) { this.a=a; } } @Test public void bindingWorked() { Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(Integer.class).toInstance(123); bind(new TypeLiteral<A<Integer>>() {}); } }); A<Integer> a = injector.getInstance( Key.get(new TypeLiteral<A<Integer>>(){})); assertEquals(new Integer(123),a.a); } } 
Sign up to request clarification or add additional context in comments.

1 Comment

@MairbekKhadikov, I plan to do so, thanks, but SO doesn't let you accept your own answer for 24 hours.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.