title: What does <T> before the return type of a method mean?
body: <p>The following method returns a List composed of <code>T</code> type elements:</p>
  
  <pre><code>public &lt;T&gt; List&lt;T&gt; getList() {
      return new ArrayList&lt;T&gt;();
  }
  </code></pre>
  
  <p>In the signature we have <code>&lt;T&gt; List&lt;T&gt;</code>. The <code>List&lt;T&gt;</code> makes sense, because that is the type of the <strong>return value</strong>.  What is the need for the preceding <code>&lt;T&gt;</code> though?</p>
  
  <p>The code doesn't compile without both <code>&lt;T&gt;</code> and <code>List&lt;T&gt;</code>. Leaving out the <code>&lt;T&gt;</code> gives</p>
  
  <blockquote>
    <p>Cannot resolve symbol T</p>
  </blockquote>
  
  <hr>
  
  <p>I have read the official Oracle tutorial on <a href="https://docs.oracle.com/javase/tutorial/java/generics/methods.html" rel="nofollow noreferrer">generic methods</a>. It explains that this is part of the syntax:</p>
  
  <blockquote>
    <p>The syntax for a generic method includes a list of type parameters, inside angle brackets, which appears before the method's return type.</p>
  </blockquote>
  
  <p>But it does not really explain why it is needed in the first place or what exact effect it has on the method.</p>