I'm going through Scala book.
Here is example:
def toInt(s: String): Option[Int] = {
try {
Some(Integer.parseInt(s.trim))
} catch {
case e: Exception => None
}
}
val x = null
println(toInt(x)) // < ---- why compiler does not complain about Null ?
toInt should allow only String as an argument, but compiler is ok with null.
Why ? Such kind of behavior is disallowed in Rust and TypeScript.
Is there any flag or smth ?
nullunchecked is very possibly the worst decision in Scala. It looks like Dotty may have something to say about it, for what it's worthStringthat includednulletc. 2. Similarly for Rust: is had not to be compatible with any toxic legacy type annotations, so it did the right thing, and eliminatednullas concept altogether.