title: How do I return List<String> from a method where I sent to put(Object) into a map (got example)
body: <p>I have the following code</p>
  
  <pre><code>private Map&lt;KEY, Object&gt; values = new HashMap&lt;KEY, Object&gt;();
  
  public void set(KEY key, Object value) {
      values.put(key, value);
  }
  
  private Object getObj(KEY key) {
      return values.get(key) == null ? key.getDefaultValue() : values.get(key);
  }
  
  public List&lt;E&gt; getList(KEY key) {
      return (List&lt;E&gt;) getObj(key);
  }
  </code></pre>
  
  <p>The idea to be able to send in any Objects in a map and then retrieve it, but how do I solve the genereics-part in java? </p>
  
  <p>Here is an example code. Here I save the List into the map:</p>
  
  <pre><code>    List&lt;String&gt; list = new ArrayList&lt;String&gt;();
  
      list.add("a string");
  
      session.set(KEY.LIST, list);
  </code></pre>
  
  <p>Now I want to get the List again:</p>
  
  <pre><code>List&lt;String&gt; list = session.getList(KEY.LIST);
  </code></pre>
  
  <p>But now I get a </p>
  
  <pre><code>cannot convert from List&lt;E&gt; to List&lt;String&gt;
  </code></pre>
  
  <p>error for obvious reasons.</p>
  
  <p>Is it possible to get a List(String) from the method, without any typecasts? Is this method correct?</p>
  
  <pre><code>public List&lt;E&gt; getList(KEY key) {
      return (List&lt;E&gt;) getObj(key);
  }
  </code></pre>