title: Kotlin: Returning Array<E> from function with return type Array<I> if E is enum class that implements interface I
body: <p>Recently I ran into a problem where I had a function which had to return an Array of <code>I</code>s, in form of all values of enum <code>E</code>, with <code>E</code> implementing interface <code>I</code>, with every code that came to my mind compiler complained about type mismatch:</p>
  
  <pre><code>Error:(x, x) Kotlin: Type mismatch: inferred type is Array&lt;E&gt; but Array&lt;I&gt; was expected
  </code></pre>
  
  <p>A minimal example:</p>
  
  <pre><code>    interface I {}
      enum class E: I {
          A, B, C;
      }
      fun getMoreInterfaces(): Array&lt;I&gt; {
          return E.values()
      }
  </code></pre>
  
  <p>This happens when trying to assign <code>E.values()</code> to variable of type <code>Array&lt;I&gt;</code>
  I am positive that this should be possible since <code>E</code> implements <code>I</code>.</p>
  
  <p>Another thing that I came up while testing is that it works just fine when used like this:</p>
  
  <pre><code>    interface I {}
      enum class E: I {
          A, B, C;
      }
      fun getMoreInterfaces(): Array&lt;I&gt; {
          return arrayOf(E.A, E.B, E.C)
      }
  </code></pre>
  
  <p>I did a lot of searching on this topic but with no luck (perhaps I chose the wrong way to describe it?)</p>