Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why in Scala Long cannot in initialized to null whear as Integer can

I am creating my Scala bean which is a configuration to be loaded from a YML config. I want a long property to be null if not specified, but I'm facing below issue. Any idea why?

startOffset: Integer = null
scala> var endOffset: Long = null
<console>:11: error: an expression of type Null is ineligible for implicit conversion
   var endOffset: Long = null
                         ^`

PS: Yes I can use Option[Long] but wanted clarity and is there anything wrong with this approach.

like image 718
mukh007 Avatar asked Aug 29 '16 16:08

mukh007


1 Answers

Scala Long is literal data type like long in Java. Same is true for Int. But Integer is a Wrapper class i.e java.lang.Integer

If you want nullable Long value, you can use java.lang.Long

like image 73
TheKojuEffect Avatar answered Nov 15 '22 20:11

TheKojuEffect