title: Simple Type Inference in Scala
body: <p>I have been looking at type inference in Scala and there are a couple of things I'd like to understand a bit better around why expression/method-return types have to be explicitly declared in a few cases.</p>
  
  <p><strong>Explicit <code>return</code> declaration</strong></p>
  
  <p>Example (works if <code>return</code> keyword is ommitted):</p>
  
  <pre><code>def upCase(s: String) = {
    if (s.length == 0)
      return s    // COMPILE ERROR - forces return type of upCase to be declared.
    else
      s.toUpperCase()
  }
  </code></pre>
  
  <p>Why can't I use the explicitly typed parameter as a return value without declaring the return type? And that's not only for direct parameter references, just for any 'type-inferable' expression.</p>
  
  <p><strong>Method overloading</strong></p>
  
  <p>Example (fails to compile when the second <code>joiner</code> method is added):</p>
  
  <pre><code>def joiner(ss: List[String], sep: String) = ss.mkString(sep)
  
  def joiner(ss: List[String]) = joiner(strings, " ")   // COMPILE ERROR WHEN ADDED
  </code></pre>