title: How to mix-in a trait to instance?
body: <p>Given a trait <code>MyTrait</code>:</p>
  
  <pre><code>trait MyTrait {
    def doSomething = println("boo")
  }
  </code></pre>
  
  <p>it can be mixed into a class with <code>extends</code> or <code>with</code>:</p>
  
  <pre><code>class MyClass extends MyTrait
  </code></pre>
  
  <p>It can also be mixed upon instantiating a new instance:</p>
  
  <pre><code>var o = new MyOtherClass with MyTrait
  o.doSomething
  </code></pre>
  
  <p>But...can the trait (or any other if that makes a difference) be added to an existing instance?</p>
  
  <p>I'm loading objects using JPA in Java and I'd like to add some functionality to them using traits. Is it possible at all?</p>
  
  <p>I'd like to be able to mix in a trait as follows:</p>
  
  <pre><code>var o = DBHelper.loadMyEntityFromDB(primaryKey);
  o = o with MyTrait //adding trait here, rather than during construction
  o.doSomething
  </code></pre>