title: How to update data classes implementing a common interface
body: <p>I'm struggling with data classes and polymorphism. I want to benefit from the immutability, but still be able to update my state. For this, I'm hoping to be able to use the <code>copy</code> function.</p>
  
  <p>Let's give an example. I have this class hierarchy:</p>
  
  <pre><code>interface Aging {
    val age : Int
  }
  
  data class Cheese (
    override val age : Int
    // more Cheese specific properties
  ) : Aging
  
  data class Wine (
    override val age : Int,
    val grape : String
    // more Wine specific properties
  ) : Aging   
  </code></pre>
  
  <p>And now I want to be able to do something like this (but <em>this</em> does not work):</p>
  
  <pre><code>class RipeningProcess(){
    fun ripen(products : List&lt;Aging&gt;) =
      // Not possibe, no copy function on Aging
      products.map { it.copy(age = it.age + 1) } 
  }
  </code></pre>
  
  <p><strong>How can I create updated copies in a polymorphic way?</strong>  </p>
  
  <p>I've tried to give the interface a <code>copy</code> function, but if the subtypes have additional properties they don't override the copy function.<br>
  It's frustrating since I <em>know</em> the subtypes have that property, but I cannot utilize that knowledge in the interface.</p>