title: Kotlin type erasure - why are functions differing only in generic type compilable while those only differing in return type are not?
body: <p>While working on the <a href="https://stackoverflow.com/a/51653302/6202869">answer</a> of <a href="https://stackoverflow.com/q/42916801/6202869">How does erasure work in Kotlin?</a> I found out some things I did not yet understand, nor did I find any sources why it is that way.</p>
  
  <p>Why is the following not compilable?</p>
  
  <pre><code>fun bar(foo: List&lt;*&gt;) = ""
  fun bar(foo: List&lt;*&gt;) = 2
  </code></pre>
  
  <p>while the following is?</p>
  
  <pre><code>fun bar(foo: List&lt;String&gt;) = ""
  fun bar(foo: List&lt;Int&gt;) = 2
  </code></pre>
  
  <p>For me it even gets more curious, when adding a generic type that isn't even used, i.e. the following compiles too:</p>
  
  <pre><code>fun bar(foo: List&lt;*&gt;) = ""
  fun &lt;T&gt; bar(foo: List&lt;*&gt;) = 2 // T isn't even used
  </code></pre>
  
  <p>As the last one doesn't even use <code>T</code> and as we know, generics are erased at runtime, why does this one work, while the variant without generic type does not? </p>
  
  <p>Within the byte code methods only differing in return type are allowed (already described in the <a href="https://stackoverflow.com/a/51653302/6202869">above linked answer</a>).</p>
  
  <p>Any hints, sources and/or references are welcome.</p>
  
  <p>Added <a href="https://discuss.kotlinlang.org/t/kotlin-type-erasure-why-are-functions-differing-only-in-generic-type-compilable-while-those-only-differing-in-return-type-are-not/9265" rel="nofollow noreferrer">this question now also at discuss.kotlinlang.org</a>.</p>