title: How does the Java compiler choose the runtime type for a parameterized type with multiple bounds?
body: <p>I would like to understand better what happens when the Java compiler encounters a call to a method like the one below.</p>
  
  <pre><code>&lt;T extends AutoCloseable &amp; Cloneable&gt;
  void printType(T... args) {
      System.out.println(args.getClass().getComponentType().getSimpleName());
  }
  
  // printType() prints "AutoCloseable"
  </code></pre>
  
  <p>It is clear to me that there is no type <code>&lt;T extends AutoCloseable &amp; Cloneable&gt;</code> at runtime, so the compiler makes the least wrong thing it can do and creates an array with the type of one of the two bounding interfaces, discarding the other one.</p>
  
  <p>Anyway, if the order of the interfaces is switched, the result is still the same.</p>
  
  <pre><code>&lt;T extends Cloneable &amp; AutoCloseable&gt;
  void printType(T... args) {
      System.out.println(args.getClass().getComponentType().getSimpleName());
  }
  
  // printType() prints "AutoCloseable"
  </code></pre>
  
  <p>This led me to do some more investigation and see what happens when the interfaces change.
  It seems to me that the compiler uses some kind of strict order rule to decide which interface is the <em>most important</em>, and the order the interfaces appear in code plays no role.</p>
  
  <pre><code>&lt;T extends AutoCloseable &amp; Runnable&gt;                             // "AutoCloseable"
  </code></pre>
  
  
  
  <pre><code>&lt;T extends Runnable &amp; AutoCloseable&gt;                             // "AutoCloseable"
  </code></pre>
  
  
  
  <pre><code>&lt;T extends AutoCloseable &amp; Serializable&gt;                         // "Serializable"
  </code></pre>
  
  
  
  <pre><code>&lt;T extends Serializable &amp; AutoCloseable&gt;                         // "Serializable"
  </code></pre>
  
  
  
  <pre><code>&lt;T extends SafeVarargs &amp; Serializable&gt;                           // "SafeVarargs"
  </code></pre>
  
  
  
  <pre><code>&lt;T extends Serializable &amp; SafeVarargs&gt;                           // "SafeVarargs"
  </code></pre>
  
  
  
  <pre><code>&lt;T extends Channel &amp; SafeVarargs&gt;                                // "Channel"
  </code></pre>
  
  
  
  <pre><code>&lt;T extends SafeVarargs &amp; Channel&gt;                                // "Channel"
  </code></pre>
  
  
  
  <pre><code>&lt;T extends AutoCloseable &amp; Channel &amp; Cloneable &amp; SafeVarargs&gt;    // "Channel"
  </code></pre>
  
  <p><strong>Question:</strong>
  How does the Java compiler determine the component type of a varargs array of a parameterized type when there are multiple bounds?</p>
  
  <p>I'm not even sure if the JLS says anything about this, and none of the information I found by googling covers this particular topic.</p>