Skip to content

Insight and analysis of technology and business strategy

Scala: generics, primitive types and nulls

While working on a Scala (2.12.4) project, I made a typo in my code and received an interesting output:

scala> new Get[Int]().inner() == null <console>:13: warning: comparing values of types Int and Null using `==' will always yield false new Get[Int]().inner() == null ^ res0: Boolean = true 

While it was an absolutely useless construction, it still causes such misleading output as seen above:

class Get[T]() { val x: T = inner() def inner(): T = x } new Get[Int]().inner() == null 

I would say that this is a minor Scala bug and probably is a side effect of some of value type + null bugs and other bugs, bugs.

Top Categories

  • There are no suggestions because the search field is empty.

Tell us how we can help!