final classOptRef[+A >: Null] extends AnyVal with Serializable
Like Opt but has better Java interop thanks to the fact that wrapped value has type A instead of Any.
For example, Scala method defined like this:
def takeMaybeString(str: OptRef[String]): Unit
will be seen by Java as:
public void takeMaybeString(String str);
and null will be used to represent absence of value.
This comes at the cost of A having to be a nullable type. Also, empty value is represented internally using null
which unfortunately makes OptRef suffer from SI-7396 (hashCode fails on OptRef.Empty which means that you
can't add OptRef values into hash sets or use them as hash map keys).
Like Opt but has better Java interop thanks to the fact that wrapped value has type
Ainstead ofAny. For example, Scala method defined like this:will be seen by Java as:
public void takeMaybeString(String str);and
nullwill be used to represent absence of value.This comes at the cost of
Ahaving to be a nullable type. Also, empty value is represented internally usingnullwhich unfortunately makes OptRef suffer from SI-7396 (hashCodefails onOptRef.Emptywhich means that you can't add OptRef values into hash sets or use them as hash map keys).Author: ghik Created: 07/01/16.