title: How to do same operation on custom objects that share same variables in Kotlin?
body: <p>I have a sealed class containing custom data classes. Some of these data classes store the same variable x like:</p>
  <pre><code>sealed class Example {
          data class foo1(var timestamp: String?, var model1: Model1?): Example() 
          data class foo2(var timestamp: String?, var model2: Model2?): Example() 
          data class foo3(var model3: Model3?): Example() 
  }
  </code></pre>
  <p>Model3 should also contain a timestamp variable.</p>
  <p>What I'm trying to do is something like this:</p>
  <pre><code>when(foo) {
         is Foo1, is Foo2 -&gt; {
           //run same piece of code
           foo.timestamp = ts
         }
         is Foo3 -&gt; {
           //run diff piece of code
           foo.model3.timestamp = ts
         }
  }
  </code></pre>
  <p>But I am having issues with this because I am getting unresolved reference with &quot;timestamp&quot; when doing the above on the first &quot;is&quot; block.
  It only works when I individually reference each type and run the same block of code for each which looks really ugly with more object types.</p>
  <p>Is there a way I can do the above and have it work, or any suggestions on if I should restructure anything with my approach to get this to work?</p>