title: Java generic, use methods of original class
body: <p>What I want to do is, create a function that returns a String with generic arguments. Then I need to use a method getName() that is for the specific class (better explain with the code).</p>
  
  <p>Here is the code: </p>
  
  <pre><code>protected StringBuilder createJSON(Collection&lt;E&gt; jsonData) {
          StringBuilder JSONBuilder = new StringBuilder();
          JSONBuilder.append("{\"options\":[");
          int count = jsonData.size();
          for(Object obj: jsonData) {
              count--;
              JSONBuilder.append("{\"label\":\"" + obj.getName() + "\",\"value\":\"" + obj.getName() + "\"}");
              if(count&gt;0) {
                  JSONBuilder.append(",");
              }
          }
          JSONBuilder.append("]}");
  
          return JSONBuilder;
      }
  </code></pre>
  
  <p>createJSON takes a generic collection of objects, the problem is when I need to use getName(). the object that I pass to this function are com.opensymphony.user.UserManager and com.atlassian.jira.ComponentManager, both with getName() method.</p>