title: How can I determine the class of an object in Scala?
body: <p>I need to check that <strong>y</strong> is strictly an instance of <strong>bar</strong> AND NOT <strong>foo</strong>. How can I do this in Scala?</p>
  
  <pre><code>trait foo {}
  
  trait bar extends foo {}
  
  val x = new foo {}
  val y = new bar {}
  
  x.isInstanceOf[foo] // true
  x.isInstanceOf[bar] // false
  
  y.isInstanceOf[bar] // true
  y.isInstanceOf[foo] // true (but I want it to return false)
  </code></pre>