title: Java generic type with wildcard
body: <p>I want to write a method that can accept the parameter:</p>
  
  <pre><code>Map&lt;String, [the type here could be anything]&gt;
  </code></pre>
  
  <p>So, here is what I coded:</p>
  
  <pre><code>/**
   * Get list value from a map, empty list if there's no key matched 
   */
  private List&lt;? extends Object&gt; getListValueFromMap(Map&lt;String, List&lt;? extends Object&gt;&gt; map, String key) {
      List&lt;? extends Object&gt; list = map.get(key);
      return list == null ? EMPTY_LIST : list;
  }
  </code></pre>
  
  <p>And the <code>EMPTY_LIST</code> is defined as below:</p>
  
  <pre><code>List&lt;Object&gt; EMPTY_LIST = Collections.unmodifiableList(new ArrayList&lt;Object&gt;());
  </code></pre>
  
  <p>The problem is that when I call this method with following code, Eclipse tells me a error that the given parameter's type is not applicable.</p>
  
  <pre><code>getListValueFromMap(cityNameMap, "key");
  </code></pre>
  
  <p>And the error is:</p>
  
  <blockquote>
    <p><code>The method getListValueFromMap(Map&lt;String,List&lt;? extends Object&gt;&gt;, String) in the type ChinaAreaResource is not applicable for the arguments (Map&lt;String,List&lt;City&gt;&gt;, String)</code></p>
  </blockquote>
  
  <p>Where am I going wrong with this?</p>
  
  <p>Here is the definition of <code>cityNameMap</code>:</p>
  
  <pre><code>/** map city's name to city list */
  private Map&lt;String, List&lt;City&gt;&gt; cityNameMap;
  </code></pre>