Yes. Optional will not just magically eradicate all our NPEs. But it is possible to write better code using Optional. As I said in the above post itself,
"The advantage compared to the normal null references is that the Optional types forces you — or the client of your API — to think about the case when the value is not present."
So now the client of the APIs should check whether the Optional has value or not before using it. For a non-optional variable, they can assume it will never be null. For Kotlin the system itself won't allow null reference to a non-optional. But in Java, we have to ensure we don't mistakenly allow a null reference to a non-optional field.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yes. Optional will not just magically eradicate all our NPEs. But it is possible to write better code using Optional. As I said in the above post itself,
"The advantage compared to the normal null references is that the Optional types forces you — or the client of your API — to think about the case when the value is not present."
So now the client of the APIs should check whether the Optional has value or not before using it. For a non-optional variable, they can assume it will never be null. For Kotlin the system itself won't allow null reference to a non-optional. But in Java, we have to ensure we don't mistakenly allow a null reference to a non-optional field.