3 ms·
Well, not really. What Kotlin has is exactly an Optional type. It's just a different syntax for it.
by chaosite 8y ago
Well, not really. What Kotlin has is exactly an Optional type. It's just a different syntax for it.
- Zarel 8y agoThere's one difference between nullable/non-nullable types and Optional type, which is nesting, right? I'd assume that while Kotlin's String? is equivalent to Optional<String>, Kotlin has no equivalent to Optional<Optional<String>>. Which, personally, I think I'd prefer Kotlin's approach, because that means you can do `maybeString = "exists"`, which is more readable than `maybeString = Optional::Exists("exists")`
- chaosite 8y agoSure. In Haskell you join them, but just not allowing it perhaps better. Also, you can still nest them in Kotlin, since you can have a nullable type inside generics.