an expression of type Null is ineligible for implicit conversion

后端 未结 1 2107
误落风尘
误落风尘 2021-01-04 09:59

When doing this:

  def myfunction(line: String): (Int, Option[DateTime], Option[Int]) = {
    // do some stuff
    (5, Option(null), Option(null))
  }


        
相关标签:
1条回答
  • 2021-01-04 10:50

    Option(null) has a lower bound of Option[Null], where Null is the bottom-type of all reference types. Int is a value type, and not a reference type. i.e. you can't assign null to an Int. So you can't assign Option[Null] to Option[Int].

    Use Option.empty[Int] or None instead.

    0 讨论(0)
提交回复
热议问题