title: Inject generics in guice with typeliteral but typeliteral constructor is protected
body: <p>I have started learning guice and stumbled upon using guice to inject generic types. All the solutions in the net seems to use something like <code>new TypeLiteral&lt;Generic&lt;Type&gt;&gt;(){}</code>. However, when I'm trying to do this, it shows that constructor of <code>TypeLiteral</code> is protected. How can I perform generic injection using <code>TypeLiteral.get()</code>? Sample code:</p>
  
  <pre><code>public interface Repository&lt;T&gt; {
    void save(T item);
    T get(int id);
  }
  
  public StringRepository implements Repository&lt;String&gt; {
    @Override
    public void save(String item) {
      // do saving
  
    }
   @Override
   public String get(int id) {
     // get item and return
     return item;
   }
  }
  
  public MyModule extends AbstractModule{
     @Override
     public void configure() {
        ....
      TypeLiteral&lt;Repository&lt;String&gt;&gt; typeLiteral =
                    TypeLiteral.get((Repository&lt;String&gt;.class));//does not work
  
      //does not work either because constructor is protected
      bind(new TypeLiteral&lt;Repository&lt;String&gt;&gt;(){}).to(StringRepository.class); 
  
  }
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/mQTDE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mQTDE.png" alt="Screenshot of my problem"></a></p>