title: Access generic type parameter at runtime?
body: <p>Event dispatcher interface</p>
  
  <pre><code>public interface EventDispatcher {
      &lt;T&gt; EventListener&lt;T&gt; addEventListener(EventListener&lt;T&gt; l);
      &lt;T&gt; void removeEventListener(EventListener&lt;T&gt; l);
  }
  </code></pre>
  
  <p>Implementation</p>
  
  <pre><code>public class DefaultEventDispatcher implements EventDispatcher {
  
  @SuppressWarnings("unchecked")
  private Map&lt;Class, Set&lt;EventListener&gt;&gt; listeners = new HashMap&lt;Class, Set&lt;EventListener&gt;&gt;();
  
  public void addSupportedEvent(Class eventType) {
      listeners.put(eventType, new HashSet&lt;EventListener&gt;());
  }
  
  @Override
  public &lt;T&gt; EventListener&lt;T&gt; addEventListener(EventListener&lt;T&gt; l) {
      Set&lt;EventListener&gt; lsts = listeners.get(T); // ****** error: cannot resolve T
      if (lsts == null) throw new RuntimeException("Unsupported event type");
      if (!lsts.add(l)) throw new RuntimeException("Listener already added");
      return l;
  }
  
  @Override
  public &lt;T&gt; void removeEventListener(EventListener&lt;T&gt; l) {
      Set&lt;EventListener&gt; lsts = listeners.get(T); // ************* same error
      if (lsts == null) throw new RuntimeException("Unsupported event type");
      if (!lsts.remove(l)) throw new RuntimeException("Listener is not here");
  }
  
  }
  </code></pre>
  
  <p>Usage</p>
  
  <pre><code>    EventListener&lt;ShapeAddEvent&gt; l = addEventListener(new EventListener&lt;ShapeAddEvent&gt;() {
          @Override
          public void onEvent(ShapeAddEvent event) {
              // TODO Auto-generated method stub
  
          }
      });
      removeEventListener(l);
  </code></pre>
  
  <p>I've marked two errors with a comment above (in the implementation). Is there any way to get runtime access to this information?</p>