title: How does the NotNull trait work in 2.8 and does anyone actually use it?
body: <pre><code>trait NotNull {}
  </code></pre>
  
  <p>I've been trying to see how this trait can guarantee that something is not null and I can't figure it out:</p>
  
  <pre><code>def main(args: Array[String]) {
    val i = List(1, 2) 
    foo(i) //(*)
  }
  
  def foo(a: Any) = println(a.hashCode)
  
  def foo(@NotNull a: Any) = println(a.hashCode) //compile error: trait NotNull is abstract
  
  def foo(a: Any with NotNull) = println(a.hashCode) //compile error: type mismatch at (*)
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>val i = new Object with NotNull //compile-error illegal inheritance
  </code></pre>
  
  <p>There is obviously some special compiler treatment going on because this compiles:</p>
  
  <pre><code>trait MyTrait {}
  
  def main(args: Array[String]) {
    val i: MyTrait = null
    println(i)
  }
  </code></pre>
  
  <p>Whereas this does not:</p>
  
  <pre><code>def main(args: Array[String]) {
    val i: NotNull = null //compile error: found Null(null) required NotNull
    println(i)
  } 
  </code></pre>
  
  <p><strong>EDIT:</strong> <em>there's nothing about this I can find in programming in Scala</em></p>