[ https://issues.apache.org/jira/browse/JDO-751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15153660#comment-15153660 ]
Renato Garcia commented on JDO-751: ----------------------------------- {quote} I still don't get the difference between empty and null. Optional does have a ofNullable() method, which can be used to set it to null. Otherwise, how do you set it to be `empty`? {quote} You use Optional.empty(). Again, the idea of Optional is to abstract {{null}} away. In the Optional world there are absolutely no nulls, and no {{null}} references which would invalidate the whole concept as we talked before. Once using Optional everything that is non-Optional is automatically assumed to be non-nullable. You need to pick one approach and delimit this world well. With this idea in mind, {{Optional.ofNullable()}} is for interoperability with the non-Optional world because {{null}} is still out there. Also, note that you are not "setting" {{null}}, because Optional is immutable, so you get back a reference that represents empty. Equally you don't obtain {{null}} from an Optional - you have to explicitly convert it back to {{null}}, which you'd only do when you need to go back to non-Optional world. {{Optional.get}} will never give you back a {{null}}, it raises an {{NoSuchElementException}}, therefore the code below will always throw an exception: {{Optional.ofNullable(null).get() == null}} So you'd need to do something like: {{ Optional<?> fooOpt = Optional.ofNullable(null); boolean expr = (fooOpt.isPresent() ? fooOpt.get() : null) == null; }} or {{Optional.ofNullable(null).orElse(null) == null}} > Support for Java8 Optional > -------------------------- > > Key: JDO-751 > URL: https://issues.apache.org/jira/browse/JDO-751 > Project: JDO > Issue Type: New Feature > Components: specification, tck > Reporter: Andy Jefferson > > java.util.Optional provides a feature that is available in other languages. > Since JDO 3.2 will be for Java8+ then it makes sense to add support for this > as a "supported persistable type" -- This message was sent by Atlassian JIRA (v6.3.4#6332)