title: Why does this getOrElse statement return type ANY?
body: <p>I am trying to follow the tutorial <a href="https://www.jamesward.com/2012/02/21/play-framework-2-with-scala-anorm-json-coffeescript-jquery-heroku" rel="noreferrer">https://www.jamesward.com/2012/02/21/play-framework-2-with-scala-anorm-json-coffeescript-jquery-heroku</a> but of course play-scala has changed since the tutorial (as seems to be the case with every tutorial I find).  I am using 2.4.3 This requires I actually learn how things work, not necessarily a bad thing.</p>
  
  <p>One thing that is giving me trouble is the getOrElse method.</p>
  
  <p>Here is my Bar.scala model</p>
  
  <pre><code>package models
  
  import play.api.db._
  import play.api.Play.current
  import anorm._
  import anorm.SqlParser._
  
  case class Bar(id: Option[Long], name: String)
  
  object Bar {
  
    val simple = {
      get[Option[Long]]("id") ~
      get[String]("name") map {
        case id~name =&gt; Bar(id, name)
      }
    }
  
    def findAll(): Seq[Bar] = {
      DB.withConnection { implicit connection =&gt;
        SQL("select * from bar").as(Bar.simple *)
      }
    }
  
    def create(bar: Bar): Unit = {
      DB.withConnection { implicit connection =&gt;
        SQL("insert into bar(name) values ({name})").on(
          'name -&gt; bar.name
        ).executeUpdate()
      }
    }
  
  }
  </code></pre>
  
  <p>and my BarFormat.scala Json formatter</p>
  
  <pre><code>package models
  
  import play.api.libs.json._
  import anorm._
  
  package object Implicits {
    implicit object BarFormat extends Format[Bar] {
      def reads(json: JsValue):JsResult[Bar] = JsSuccess(Bar(
        Option((json \ "id").as[Long]),
        (json \ "name").as[String]
      ))
  
      def writes(bar: Bar) = JsObject(Seq(
        "id" -&gt; JsNumber(bar.id.getOrElse(0L)),
        "name" -&gt; JsString(bar.name)
      ))
  
    }
  }
  </code></pre>
  
  <p>and for completeness my Application.scala controller:</p>
  
  <pre><code>package controllers
  
  import play.api.mvc._
  import play.api.data._
  import play.api.data.Forms._
  import javax.inject.Inject
  import javax.inject._
  import play.api.i18n.{ I18nSupport, MessagesApi, Messages, Lang }
  import play.api.libs.json._
  
  import views._
  import models.Bar
  import models.Implicits._
  
  class Application  @Inject()(val messagesApi: MessagesApi) extends Controller  with I18nSupport {
  
    val barForm = Form(
      single("name" -&gt; nonEmptyText)
    )
  
    def index = Action {
      Ok(views.html.index(barForm))
    }
  
    def addBar() = Action { implicit request =&gt;
      barForm.bindFromRequest.fold(
        errors =&gt; BadRequest,
        {
          case (name) =&gt;
            Bar.create(Bar(None, name))
            Redirect(routes.Application.index())
        }
      )
    }
  
    def listBars() = Action { implicit request =&gt;
      val bars = Bar.findAll()
  
      val json = Json.toJson(bars)
  
      Ok(json).as("application/json")
  
    }
  </code></pre>
  
  <p>and routes</p>
  
  <pre><code> # Routes
   # This file defines all application routes (Higher priority routes first)
   # ~~~~
  
   # Home page
   POST       /addBar                     controllers.Application.addBar
   GET     /                           controllers.Application.index
   GET        /listBars                   controllers.Application.listBars
  
   # Map static resources from the /public folder to the /assets URL path
   GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset)
  </code></pre>
  
  <p>When I try to run my project I get the following error:</p>
  
  <p><a href="https://i.stack.imgur.com/MI5Af.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MI5Af.png" alt="Compilation Error"></a></p>
  
  <p>now bar.id is defined as an Option[Long] so bar.id.getOrElse(0L) should return a Long as far as I can tell, but it is clearly returning an Any. Can anyone help me understand why?</p>
  
  <p>Thank You!</p>