by jankotek · 9y ago · 0 comments
- Optional does not protect from NPE, null is still allowed
- It adds extra layer of complexity
- some libraries use it, some do not. it is not enforced
- extra typing, Java does not even have type inference and `val` declaration
- `if` expression in java does not return a value, no pattern matching... again far more typing
- no support for chained call on several nullable fields
I use Kotlin for couple of years. It has nullability baked into type system and enforced by the compiler. And it works with existing java libraries.
It feels like going back 15 years to Java 1.4, when I use Optional in Java8 or Scala.
Which Map are you talking about? I don't see the method that returns nulls for missing values.
> Kotlin has only single way.
... with the nice side-effect of being unable to tell whether the key didn't exist or if it was null. That's the single worst approach one can take.
Most Java Collections does not allow null keys and null values.