Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

an expression of type Null is ineligible for implicit conversion

Tags:

null

scala

When doing this:

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

I get the following:

an expression of type Null is ineligible for implicit conversion

I'm not sure how to fix it.

like image 996
Bob Avatar asked Feb 04 '16 14:02

Bob


Video Answer


1 Answers

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.

like image 155
Michael Zajac Avatar answered Sep 19 '22 03:09

Michael Zajac