Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Some(null) isn't considered None?

Tags:

null

option

scala

I am curious:

scala> Some(null) == None res10: Boolean = false 

Why isn't Some(null) transformed to None?

like image 413
Geo Avatar asked Apr 26 '11 21:04

Geo


People also ask

Does null == 0 in Java?

Below are some important points about null in java that every Java programmer should know: 1. null is Case sensitive: null is literal in Java and because keywords are case-sensitive in java, we can't write NULL or 0 as in C language.

What is some null Scala?

Null is - together with scala. Nothing - at the bottom of the Scala type hierarchy. Null is the type of the null literal. It is a subtype of every type except those of value classes. Value classes are subclasses of AnyVal, which includes primitive types such as Int, Boolean, and user-defined value classes.

What is some () in Scala?

Scala some class returns some value if the object is not null, it is the child class of option. Basically, the option is a data structure which means it can return some value or None. The option has two cases with it, None and Some. We can use this with the collection.

WHAT IS NULL value in Java?

Null serves as the default value of any uninitialized reference variable, including instance variables and static variables (although you will still receive a compiler warning for uninitialized local variables).


1 Answers

You should use Option(null) to reach the desired effect and return None.

Some(null) just creates a new Option with a defined value (hence Some) which is actually null, and there are few valid reasons to ever create one like this in real code.

like image 62
Jean-Philippe Pellet Avatar answered Nov 11 '22 00:11

Jean-Philippe Pellet