title: Kotlin - type mismatch with generic return type and subclass
body: <p>I hope everybody is staying healthy amid this pandemic :)</p>
  
  <p>I could use some help figuring out what I'm doing wrong here, TIA! Also, I'm a little new to Kotlin so sorry if this is a dumb question.</p>
  
  <p>I'm trying to extend a class and implement an interface that are defined in a java library (AndroidX). However, when I try to implement the interface function I get a type mismatch error with my return value. Since I'm using an interface defined in the AndroidX library, simply changing the interface function signature to make it build is not an option.</p>
  
  <p>I'm basically converting this other SO answer to Kotlin: <a href="https://stackoverflow.com/a/34398747/535638">https://stackoverflow.com/a/34398747/535638</a></p>
  
  <p>Dev machine/IDE info:
  Android Studio 3.6.1
  Build #AI-192.7142.36.36.6241897, built on February 26, 2020
  Runtime version: 1.8.0_212-release-1586-b04 amd64
  VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
  Windows 8.1 6.3
  GC: ParNew, ConcurrentMarkSweep
  Memory: 1237M
  Cores: 8
  Registry: ide.new.welcome.screen.force=true
  Non-Bundled Plugins: org.jetbrains.kotlin, com.google.services.firebase</p>
  
  <p>I tried to generalize this error with the code below, to hopefully save you some effort in grokking the other SO question, and I'm getting the same compiler error with this generalized code.</p>
  
  <pre><code>open class LibraryClassA {
  
  }
  
  open class LibraryClassB {
      val retval = LibraryClassA()
  
      // this kotlin signature seems to be inferred/transcribed from java by the IDE/compiler
      open fun &lt;T : LibraryClassA?&gt; foobar(): T? {
          return null
      }
  }
  
  class MyClass : LibraryClassB() {
  
      override fun &lt;T : LibraryClassA?&gt; foobar(): T? {
          return retval // compiler error on this line - type mismatch, Required T?, Found LibraryClassA
      }
  }
  </code></pre>