title: Why does this Kotlin parameter type with an upper bound need a cast?
body: <p>The following function takes a list of <code>Serializable</code> and a lambda which serializes the individual elements of the list.</p>
  
  <pre><code>    val os = BufferOutputStream()
      fun &lt;T : Serializable&gt; writeList(list: List&lt;Serializable&gt;, emitter: (T, BufferOutputStream) -&gt; Unit) {
          os.writeInt(list.size)
          for (v in list) {        // v is of type Serializable
              emitter(v as T, os)  // why do we need to cast V as T? 
          }
      }
  </code></pre>
  
  <p>Why would I need to cast <code>v</code> which is of type <code>Serializable</code> to <code>T</code> when <code>T</code> already has to implement <code>Serializable</code>? Doesn't <code>&lt;T : Serializable&gt;</code> establish that a function/lambda that takes <code>Serializable</code> must take <code>T</code>?</p>