Possible to make scala require a non-Nothing generic method parameter and return to type-safety
<p>In scala, the shit can hit the fan if the caller of a generic method omits to explicitly specify the type parameter. For example:</p>

<pre><code>class Expression[+T] // Will have eval():T method, so +T

class NothingTest {

  def makey[T](): Expression[T] = null

  def needsBool(b: Expression[Boolean]): Unit = {}

  var b: Expression[Boolean] = null
  var n = makey()  // : Expression[Nothing]

  b=n  // Yikes.

  needsBool(n)  // :-/ Supplied Expression[Nothing] ... not a Expression[Nothing]
}
</code></pre>

<p>I'm <em>supposed</em> to supply a type parameter to <code>makey()</code> (e.g. <code>makey[Boolean]()</code> ), however in this instance I forgot, the program compiled (which, by the way, is extremely easy to do).</p>

<p>The program will eventually fail in <code>needsBool</code> (implementation omitted) which did not receive an <code>Expression[Booolean]</code> object - it got an <code>Expression[Nothing]</code> object instead. Scala's docs says Nothing is a subclass of all types, which seems exceptionally rude and is certain to break type safety wherever it appears.</p>

<p>So, to reintroduce some type-safety, can I either:</p>

<ul>
<li>prevent <code>makey</code> from returning Expression[Nothing] but requiring that a type parameter be provided? (<a href="https://stackoverflow.com/questions/3157422/avoiding-cast-to-nothing-in-generic-method">I suspect not</a>), OR</li>
<li>prevent <code>needsBool</code> from receiving an Expression[Nothing]?</li>
</ul>

<p>at compile-time.</p>

<hr>

<p>Update:</p>

<p>A fuller (compiling, but runtime failing example):</p>

<pre><code>class Expression[+T](val value:T){ 
  def eval:T = value
}

class NothingTest {

  def makey[T](): Expression[T] = new Expression[String]("blah").asInstanceOf[Expression[T]]

  def needsBool(b: Expression[Boolean]): Unit = {
    val boolval = b.eval  // Explode! String is not a Boolean
    println(boolval)
  }

  var b: Expression[Boolean] = null
  var n = makey()  // : Expression[Nothing]. You're suppose to supply a type, but forgot.
  b=n  // Yikes.
  needsBool(n)  // :-/ Supplied Expression[Nothing]
}
</code></pre>