None is the counterpart to Some, used when you're using Scala's Option class to help avoid null
references.
Scala's null
is the same as in Java.
Scala's null
is the same as in Java. Any reference type can be null
, like Strings, Objects, or your own classes. Also just like Java, value types like Ints can't be null
.
Null is a trait whose only instance is null
. It is a subtype of all reference types, but not of value types. It purpose in existing is to make it so reference types can be assigned null
and value types can't.
Nothing is a trait that is guaranteed to have _zero_ instances. It is a subtype of all other types. It has two main reasons for existing: to provide a return type for methods that **never** return normally (i.e. a method that always throws an exception). The other reason is to provide a type for Nil (explained below).
Unit in Scala is the equivalent of void
in Java. It's used in a function's signature when that function doesn't return a value.
Nil is just an empty list, exactly like the result of List()
. It is of type List[Nothing]
. And since we know there are no instances of Nothing, we now have a list that is statically verifiable as empty. Nice to have.
An empty list can be represented by another nothing value: *Nil*
Option.getOrElse
can be used to provide a default in the case of None
:
None
should be identical to None
:
None
is considered empty
None
can be cast Any
, *AnyRef* or AnyVal
None
can be converted to an empty list
None
can be converted to a *String*:
None
can be used with Option
instead of null references
Some
is the opposite of None
for Option
types
This method has been deprecated in favor of macro assertion and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assertion and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assumption and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assumption and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
Please use 'an [Exception] should be thrownBy { ... }' syntax instead
This expect method has been deprecated. Please replace all invocations of expect with an identical invocation of assertResult instead.
This expect method has been deprecated. Please replace all invocations of expect with an identical invocation of assertResult instead.
This expectResult method has been deprecated. Please replace all invocations of expectResult with an identical invocation of assertResult instead.
This expectResult method has been deprecated. Please replace all invocations of expectResult with an identical invocation of assertResult instead.