title: Quite confused about this code snippet return types with & without =
body: <pre><code>object A extends App {
  
  def closure1(x:Int) = {
    object O {
     def getX = x
     def add(y:Int) = x+y
    }
    val foo = O
    foo
  }
  
  def closure2(x:Int) {
    object O {
     def getX = x
     def add(y:Int) = x+y
    }
    val foo = O
    foo
  }
  
  println(closure1(4).getClass)
  println(closure2(4).getClass)
  }
  
  result:
   $scala A
   class A$O$3$
   void
  </code></pre>
  
  <ol>
  <li>Why are the return types different ?</li>
  <li>I really don't care about the return types. I want to call getX and add - I want to do something like closure1(4).getX - this is illegal. How do I do that ?</li>
  </ol>