title: Usage of kotlin generics "in", "out" in inheritance
body: <p>I have base class which I'm planning to use for downloading some data from server:</p>
  
  <pre><code>abstract class Processor&lt;out T : BaseEntity&gt; {
     fun loadData() {
        val data = fetchFromBackend()
        saveData(data)
     }
  
     // here I'll define specific logic of saving data
     // and here is my Error Type parameter T is declared as 'out' but occurs in 'invariant' position in type T
     abstract protected open fun saveData(data: T)
  
  }
  </code></pre>
  
  <p>Then I have multiple implementation of this <code>Processor</code> class and use them like that</p>
  
  <pre><code>val processor: EntityProcessor&lt;BaseEntity&gt; = when(type){
                 TypeA -&gt; ProcessorImplementationA(...)
                 TypeB -&gt; ProcessorImplementationB(...)
                 TypeC -&gt; ProcessorImplementationC(...)
  </code></pre>
  
  <p>To be able to safely assign implementation of processor to base type I'm using <strong>out</strong> in <code>T</code> generic declaration. But this causes the problem in <code>saveData(data: T)</code> method. If I use invariance, means no keyword before generic declaration I will not be able to safely assign implementation of <code>Processor</code> to base type</p>
  
  <p>Is there a way to implement this class hierarchy without class cast, or what is the best way to implement this?</p>