title: How to convert a type-erased list to an array in Kotlin?
body: <p>A function <code>toArray</code> should convert type-erased list to <code>T</code> that is <code>Array&lt;String&gt;</code> now.</p>
  
  <pre><code>inline fun &lt;reified T&gt; toArray(list: List&lt;*&gt;): T {
      return list.toTypedArray() as T
  }
  
  toArray&lt;Array&lt;String&gt;&gt;(listOf("a", "b", "c")) // should be arrayOf("a", "b", "c")
  </code></pre>
  
  <p>However, <code>toArray</code> throws this error.</p>
  
  <blockquote>
    <p>java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;</p>
  </blockquote>
  
  <p>Do you have any ideas?</p>