title: Error Kotlin: Type mismatch: inferred type is T? but Nothing was expected
body: <pre><code>class MyExample {
    abstract class Field&lt;in E, T : Any&gt;(private val getter: (E) -&gt; T?) {
      fun get(entity: E): T? { return getter(entity) }
    }
  
    interface Meta&lt;T: Any&gt; {
      fun getFields(): List&lt;MyExample.Field&lt;T, *&gt;&gt;
    }
  
  
    interface MetaRepository {
      fun &lt;T : Any&gt; getMeta(klass: KClass&lt;T&gt;): Meta&lt;T&gt;?
    }
  
    lateinit var metaRepository: MetaRepository
  
    fun &lt;T : Any&gt; doSomthing(entity: T?) {
  
      val meta = metaRepository.getMeta(entity!!::class)!!
  
      meta.getFields().forEach { field -&gt;
        val fieldValue = field.get(entity) // &lt;-- Error Kotlin: Type mismatch: inferred type is T? but Nothing was expected
        Unit
      }
    }
  }
  </code></pre>
  
  <p>Does anyone know why the compilation error <code>"Error Kotlin: Type mismatch: inferred type is T? but Nothing was expected"</code> is produced for the code above?
  How can I solve this error?</p>