3 ms·
Much better than using static analysis is to have it in the type system: https://kotlinlang.org/docs/reference/null-safety.html https://kotlinlang.org/docs/ref
by mike_hearn 11y ago
Much better than using static analysis is to have it in the type system:
https://kotlinlang.org/docs/reference/null-safety.html 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
- dllthomas 11y ago"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.