title: Extractor object in scala: difference between apply() and defined functions
body: <p>I'm relatively new to Scala and going through some tutorials I bumped into this code in <a href="http://docs.scala-lang.org/overviews/collections/maps.html" rel="nofollow">http://docs.scala-lang.org/overviews/collections/maps.html</a>:</p>
  
  <pre><code>import scala.collection.mutable.{Map,
  SynchronizedMap, HashMap}
  
  object MapMaker{
    def makeMap: Map[String,String] = {
      new HashMap[String,String] with SynchronizedMap[String,String]{
        override def default(key:String) = "Why do you want to know?" 
      }                                                   
    }
  }
  
  val capital = MapMaker.makeMap
  
  capital ++ List("US" -&gt; "Washington",
    "Paris" -&gt; "France", "Japan" -&gt; "Tokyo")
  </code></pre>
  
  <p>I tried to create an "apply" function inside the object and get rid of the MapMaker.makeMap syntax. So instead the code would look like this </p>
  
  <pre><code>object MapMaker{
    def apply: Map[String,String] = {
      new HashMap[String,String] with SynchronizedMap[String,String]{
        override def default(key:String) = "Why do you want to know?" 
      }                                                  
    }
  }
  
  val capital = MapMaker
  capital ++ List("US" -&gt; "Washington",
   "Paris" -&gt; "France", "Japan" -&gt; "Tokyo")
  </code></pre>
  
  <p>But it doesn't work since it returns a different kind of value</p>
  
  <pre><code>scala&gt; val capital = MapMaker
  capital: MapMaker.type = MapMaker$@105cb38b
  </code></pre>
  
  <p>I'm just doing this for the sake of learning when and how to use the "apply function" that you use in extractor objects.</p>