title: Java generic method not working - parameter not being restricted
body: <p>Say I have this code:</p>
  
  <pre><code>class Demo
  {
      static &lt;T&gt; T pick(T a1, T a2)
      {
          return a2;
      }
  
      public static void main(String[] args)
      {
          pick("d", 123);
      }
  }
  </code></pre>
  
  <p>From what I learned, it seems like I have stated that the two parameters <code>a1</code>, <code>a2</code> and the return type of <code>pick</code> must be under the same generic type <code>T</code>.</p>
  
  <p>So why is the compiler allowing me to pass a <code>String</code> and an <code>Integer</code> to <code>pick</code>?</p>