DEV Community

Discussion on: Java is Dead - Long Live Java

Collapse
 
siy profile image
Sergiy Yevtushenko

Kotlin does one right thing: clearly separates nullable and non-nullable types and lets compiler do the rest. But same thing is possible in Java by using class like Option (Optional does not always does the job) to mark nullable values. There are more details about this approach in my article

Collapse
 
gklijs profile image
Gerard Klijs

Option could still be null. There are several annotations that could help with nullability but some work compile time and some runtime, it's easy to get it wrong.

Thread Thread
 
siy profile image
Sergiy Yevtushenko

Annotations are useless. And this is just a matter of properly handling of null values coming from external code and matter of habit to use Option where value can be nullable. There should be no cases when Option itself can be null. In fact this is extremely convenient to assume that all variables are not null and removes a lot of headache and mental load. But, well, convenient use of this approach is impossible without a significant doze of functional code. Which is good too, but, of course requires changes in habits and mental model.