incompatiable types error when returning generics wildcard collection
<p>I'm working on a function that generates a two-level associative array fetched from the database. The array will be used to create an expandable list view. It needs to be a generics wild card <code>List</code> because the expandable list adapter requires that.</p>

<p>I just read from <a href="https://stackoverflow.com/questions/176446/how-can-elements-be-added-to-a-wildcard-generic-collection">another thread</a> that in order to add elements to a generics collection, <code>super</code> or <code>extend</code> has to be employed with the generics. It works okay, however, why am I getting an incompatiable types error when returning the collection? </p>

<pre><code>public HashMap&lt;String, List&lt;? super SearchField&gt;&gt; getAll() {

    HashMap&lt;String, List&lt;SearchField&gt;&gt; listCollection = new HashMap&lt;String,List&lt;SearchField&gt;&gt;();

    /************DataBase Query***************/    
    try {

        if (cursor.moveToFirst()) {

            List rowList = new ArrayList&lt;SearchField&gt;();

            do {

                SearchField sf = new SearchField();

                sf.value = cursor.getString(cursor.getColumnIndex("value"));

                sf.group_title = cursor.getString(cursor.getColumnIndex("group_title"));

                sf.key = cursor.getString(cursor.getColumnIndex("key"))

                rowList.add(sf);

                Map&lt;String,String&gt; group = (Map&lt;String,String&gt;)listCollection.get(sf.group_title);

                if(group == null){

                    listCollection.put(sf.group_title,rowList);

                }else{

                    listCollection.get(sf.group_title).add(sf);

                }


            } while(cursor.moveToNext());
        }
    } catch (Exception e) {
    } finally {
        if (cursor != null &amp;&amp; !cursor.isClosed()) {
            cursor.close();
        }
    }
    return listCollection;
           ^^^^^^^^^^^^^
}
</code></pre>

<p>SearchField Class</p>

<pre><code>public class SearchField {

    public String value;

    public String key;

    public String group_title;


}
</code></pre>

<p>I followed this example from the other thread:</p>

<pre><code>  public List&lt;? extends Foo&gt; getFoos()
  {
    List&lt;Foo&gt; foos = new ArrayList&lt;Foo&gt;(); /* Or List&lt;SubFoo&gt; */
    foos.add(new SubFoo());
    return foos;
  }
</code></pre>

<p>The two-level array I'm trying to create from the fetched result is like this in PHP:</p>

<pre><code>$group = array("A Group"=&gt;array("value"=&gt;2,"title"=&gt;"Apple"),
               "B Group"=&gt;array("value"=&gt;1,"title"=&gt;"Boy")
         )
</code></pre>

<p>Update:</p>

<p>The reason I want to return the wildcard because my expandable list adapter is used across different activities and takes collections of different structures.  </p>

<pre><code>public ExpandableListAdapter(FragmentActivity context, List&lt;String&gt; group,
        Map&lt;String, List&lt;?&gt;&gt; listCollection) {
    this.dataCollections = listCollection;
}
</code></pre>

<p>So I'd like to return a list using wild card for the adapter.</p>