title: Type T parameters not the same
body: <p>I have the following code:</p>
  <pre><code>  public static &lt;T&gt; T print(T element1, T element2){
          System.out.println(element1.getClass());
          System.out.println(element2.getClass());
          return null;
      }
  
  
      public static void main(String[] args) {
          print(10, &quot;str&quot;);
      }
  </code></pre>
  <p>It compiles, no errors. Method &quot;print&quot; accepts two arguments of the same Type (T). But I can call this method, for example, with Integer and String arguments.</p>
  <p>If I want to use return value, code doesn't compile:</p>
  <pre><code>Integer t = print(10, 20.0); //compilation error
  </code></pre>
  <p>This example also has the same behavior. I can use different types for Array and for Element (but if I use different types, I get ArrayStoreException).</p>
  <pre><code> public static &lt;T&gt; void fillArray(T[] array, T element){}
  </code></pre>
  <p>And if I work with Collections, I can't use different types. The following example doesnt compile:</p>
  <pre><code> public static &lt;T&gt; void fillList(List&lt;T&gt; list, T element){}
  
      public static void main(String[] args) {
          List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
          fillList(list, 20.0);
      }
  </code></pre>
  <p>What's the reason of such behavior? Why I can call method with different types with Arrays, and cannot with Lists, if I declared, that I have only the same type T?</p>