Re:Java 8’s new Optional type doesn't solve anything
by dllthomas on Tuesday October 27, 2015 @09:06PM
(#10462300)
"Much better than using static analysis is to have it in the type system"
I am not sure there is a distinction. Though it is true that some analyses may be run by a broader swath of users.
https://kotlinlang.org/docs/reference/null-safety.html
It's simple:
val x: Foo = maybeGetSomeFoo() // Error: method returns Foo?
val x: Foo? = maybeGetSomeFoo()
x.sayHello() // Error: x may be null
x!!.sayHello() // OK, the !! method throws an exception if it's null
if (x != null) x.sayHello() // OK, flow sensitive typing means the test narrows the type
val h = x?.sayHello() // OK, ?. yields null if left hand side is null, otherwise evaluates right
val h = x?.sayHello() ?: return // OK, ?: runs right hand side only if left hand side is null