An expression of type Null is not suitable for implicit conversion

Wherein:

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 not acceptable for implicit conversion

I am not sure how to fix this.

+5
source share
1 answer

Option(null) has a lower bound on Option[Null] , where Null is the bottom type of all reference types. Int is a value type, not a reference type. those. You cannot assign Null to Int . Therefore, you cannot assign Option[Null] Option[Int] .

Use Option.empty[Int] or None instead.

+13
source

Source: https://habr.com/ru/post/1242298/


All Articles