title: What is the point of the class Option[T]?
body: <p>I am not able to understand the point of <code>Option[T]</code> class in Scala. I mean, I am not able to see any advanages of <code>None</code> over <code>null</code>.</p>
  
  <p>For example, consider the code:</p>
  
  <pre><code>object Main{
    class Person(name: String, var age: int){
      def display = println(name+" "+age)
    }
  
    def getPerson1: Person = {
      // returns a Person instance or null
    }
  
    def getPerson2: Option[Person] = {
      // returns either Some[Person] or None
    }
  
    def main(argv: Array[String]): Unit = {
      val p = getPerson1
      if (p!=null) p.display
  
      getPerson2 match{
        case Some(person) =&gt; person.display
        case None =&gt; /* Do nothing */
      }
    }
  }
  </code></pre>
  
  <p>Now suppose, the method <code>getPerson1</code> returns <code>null</code>, then the call made to <code>display</code> on first line of <code>main</code> is bound to fail with <code>NPE</code>. Similarly if <code>getPerson2</code> returns <code>None</code>, the <code>display</code> call will again fail with some similar error.</p>
  
  <p>If so, then why does Scala complicate things by introducing a new value wrapper (<code>Option[T]</code>) instead of following a simple approach used in Java?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I have edited my code as per <a href="https://stackoverflow.com/users/164075">@Mitch</a>'s suggestion. I am still not able to see any particular advantage of <code>Option[T]</code>. I have to test for the exceptional <code>null</code> or <code>None</code> in both cases. :(</p>
  
  <p>If I have understood correctly from <a href="https://stackoverflow.com/questions/2079170/why-optiont/2079247#2079247">@Michael's reply</a>, is the only advantage of <code>Option[T]</code> is that it explicitly tells the programmer that <em>this method could return None</em>? Is this the only reason behind this design choice?</p>