title: Using generics with collection of enum classes implementing same interface
body: <p>I am trying to do <a href="https://stackoverflow.com/questions/5316311/java-enum-reverse-look-up-best-practice">reverse lookup</a> on few enum classes implementing same <code>Field</code> interface by iterating through list of <code>Class</code>es using Guava's <a href="https://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/Maps.html#uniqueIndex%28java.lang.Iterable,%20com.google.common.base.Function%29" rel="nofollow noreferrer"><code>Maps.uniqueIndex</code></a>:</p>
  
  <pre class="lang-java prettyprint-override"><code>  Field valueOfSearchName = null;
    for (final Class&lt;? extends Enum&lt;?&gt;&gt; clazz : ImmutableList.of(
        EntityField.class,
        AddressField.class,
        PersonFunctionType.class)) {
      valueOfSearchName = Fields.valueOfSearchName(clazz, term.field()); // error
      if (valueOfSearchName != null) {
        // do something...
        break;
      }
    }
  </code></pre>
  
  <p>I don't want to repeat same code (for making index and doing lookup) in all enum classes, so I use helper static class <code>Fields</code> containing <code>Fields.valueOfSearchName</code> method:</p>
  
  <pre class="lang-js prettyprint-override"><code>  public static &lt;E extends Enum&lt;E&gt; &amp; Field&gt; Field valueOfSearchName(
        final Class&lt;E&gt; clazz, final String searchName) {
      // TODO: cache the index
      final ImmutableMap&lt;String, E&gt; index = Maps.uniqueIndex(
          EnumSet.allOf(clazz), GET_SEARCH_NAME_FUNCTION);
      return index.get(searchName);
    }
  </code></pre>
  
  <p>Unfortunately, Eclipse shows an error:</p>
  
  <pre><code>Bound mismatch: 
  The generic method valueOfSearchName(Class&lt;E&gt;, String) of type Fields is not 
  applicable for the arguments (Class&lt;capture#1-of ? extends Enum&lt;?&gt;&gt;, String).
  The inferred type capture#1-of ? extends Enum&lt;?&gt; is not a valid substitute
  for the bounded parameter &lt;E extends Enum&lt;E&gt; &amp; Field&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>The problem is <code>Class&lt;? extends Enum&lt;?&gt;&gt; clazz</code> in for-each loop (not matching Field)</strong>, but I don't know how to deal with this case (obviously I cannot add <code>&amp; Field</code> to <code>clazz</code>).</p>