title: Task not serializable: java.io.NotSerializableException when calling function outside closure only on classes not objects
body: <p>Getting strange behavior when calling function outside of a closure:</p>
  
  <ul>
  <li>when function is in a object everything is working</li>
  <li>when function is in a class get : </li>
  </ul>
  
  <blockquote>
    <p>Task not serializable: java.io.NotSerializableException: testing</p>
  </blockquote>
  
  <p>The problem is I need my code in a class and not an object. Any idea why this is happening? Is a Scala object serialized (default?)?</p>
  
  <p>This is a working code example:</p>
  
  <pre><code>object working extends App {
      val list = List(1,2,3)
  
      val rddList = Spark.ctx.parallelize(list)
      //calling function outside closure 
      val after = rddList.map(someFunc(_))
  
      def someFunc(a:Int)  = a+1
  
      after.collect().map(println(_))
  }
  </code></pre>
  
  <p>This is the non-working example :</p>
  
  <pre><code>object NOTworking extends App {
    new testing().doIT
  }
  
  //adding extends Serializable wont help
  class testing {  
    val list = List(1,2,3)  
    val rddList = Spark.ctx.parallelize(list)
  
    def doIT =  {
      //again calling the fucntion someFunc 
      val after = rddList.map(someFunc(_))
      //this will crash (spark lazy)
      after.collect().map(println(_))
    }
  
    def someFunc(a:Int) = a+1
  }
  </code></pre>