Comment by paulddraper
2 days ago
Java Optional is just as safe as Kotlin Option (and predates it by a couple years).
Scala, Kotlin, Java you just can’t get away from null :/
2 days ago
Java Optional is just as safe as Kotlin Option (and predates it by a couple years).
Scala, Kotlin, Java you just can’t get away from null :/
The important distinction for me with Kotlin's system is that the compiler guides developers to write null-safe code by default because it's built into the language itself. Whereas Optional in Java requires extra effort in instantiating Optional.of(...) all over the place. Java Optional is opt-in, similar to (but weaker than) SQL `NOT NULL` - easy to forget, rather than Kotlin opt-out.
Even in safe languages like Rust, you can still introduce errors with the same semantics in application code as null pointer error: doing `some_optional.unwrap().someMethod()` will crash your program just as much as `someNullableObject.someMethod()` in Java.
Null-restricted types will be available soon I hope.