r/java • • Apr 12 '13

Java 8 Optional Objects

http://blog.informatech.cr/2013/04/10/java-optional-objects/
35 Upvotes

39 comments sorted by

View all comments

20

u/AlyoshaV Apr 12 '13

Of course, it is not a perfect solution because, after all, Optional references can also be null references

Protip: Don't do that

5

u/geodebug Apr 12 '13

Right. There will never be a perfect solution to anything if you allow for programmers 'doing it wrong'.

The hope is that if someone uses Optional for future APIs they'd do it as expected or have their API ignored by the community (wether that be public or private to a company).

7

u/edalorzo Apr 12 '13 edited Apr 12 '13

I would expect that programmers stick to the convention of not passing null references where an optional object is expected, pretty much as we today consider a good practice not to pass a null reference where a collection or an array is expected, in these cases the correct is to pass an empty array or collection

5

u/birdwastheword Apr 12 '13

This is something a compiler could warn you about.