Scala: Typed Emptiness?

72 views Asked by At

I'm wondering if it's possible to give a Type to something "empty" in Scala?

For example, I'm looking for something like Null[String] or Nothing[String] or None[String].

I'm not looking to use an Option. To be honest, what I'm doing is I have a map:

options: Map[String, Any] = Map("id" -> Null, "num" -> Null)

That other people will "extend" with:

_options: Map[String, Any] = Map("id" -> "Hi", "num" -> 5)
options = options ++ _options

And I want to be able to specify what types are suppose to be given in the map.

Thanks!

2

There are 2 answers

5
jinglining On

you can try this: val option: Map[String,Any] = Map("id" -> null)

1
jinglining On

no None is just a Object . it may like constant .