title: How parametrize generic singleton in java
body: <p>I have next problem. I have an interface:</p>
  
  <pre><code>public interface Worker&lt;T&gt; {
      public void start(Class&lt;? extends T&gt; taskClass);
  }
  </code></pre>
  
  <p>and singleton implementation of this interface:</p>
  
  <pre><code>public final class Listener&lt;T extends Runnable&gt; implements Worker&lt;T&gt; {
      private Listener() {}
  
      @Override
      public void start(Class&lt;? extends T&gt; taskClass) { ... }
  
      public static Listener getInstance() {
          return SingletonHolder.INSTANCE;
      }
  
      private static class SingletonHolder {
          public static final Listener INSTANCE = new Listener();
      }
  }
  </code></pre>
  
  <p>My question is, can I get the singleton instance by this way:</p>
  
  <pre><code>Worker&lt;Thread&gt; listener = Listener.getInstance();
  </code></pre>
  
  <p>is still type-safe? when not, how can I use generic in singleton instance to by type-safe?</p>