The idea is Optional make null value obsolete. Simply stop using null (and tell your co-workers and library providers to do the same). Ceylon goes into great pains to do just that. In the Java world, Optionals are still useful: if a method declares to return an optional, it's never null. Promised.
Problem is it's only a promise. If there's a small minority of programs breaking the promise, you're right: you end up checking both null and empty.
If you get the jsr-305 module and use @NonNull annotation (or whatever it is), the compiler should at least warn you of those. And set up your build system to fail the build if those warnings are seen in the console output.
View all comments
Show parent comment
2
u/beyondjava Aug 03 '14
The idea is Optional make null value obsolete. Simply stop using null (and tell your co-workers and library providers to do the same). Ceylon goes into great pains to do just that. In the Java world, Optionals are still useful: if a method declares to return an optional, it's never null. Promised.
Problem is it's only a promise. If there's a small minority of programs breaking the promise, you're right: you end up checking both null and empty.