Provide class in notnull in Scala?

Since the NotNull flag is deprecated, what is the new best way to declare my classes invalid?

There is still a compiler option (does not prevent someone from abusing my libraries in other projects). Along with several conflicting Java annotations, which I doubt the Scala compiler will respect.

+3
source share
1 answer

You should not use nullScala at all, and if you do not, there is no need to use a tag NotNull.

If you have values ​​or variables that may have “no value,” use a type Optioninstead of a value null. Optionhas two subclasses: Someand None.

// text is "None", which means it has no value
var text: Option[String] = None

// Use "Some" when it should have a value
text = Some("Hello World")

Option ; ( ) , , .

text match {
  case Some(s) => println("Text: " + s)
  case None    => println("Empty")
}
+2

All Articles