[
https://issues.apache.org/jira/browse/JDO-751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15143012#comment-15143012
]
Craig L Russell commented on JDO-751:
-------------------------------------
I'd like to propose that Optional be strictly a persistence-capable class
modeling artifact.
For mapping to the datastore, treat Optional<T> exactly as T, except (as Andy
suggests) require that the datastore accept null as a value. When instantiating
an instance from the datastore, the persistence implementation would get the
value v from the datastore and assign the field f = Optional<T>.ofNullable(v).
When storing the field in the datastore, the persistence implementation would
store the result of v = f.isPresent()?f.get():null.
With this proposal, there is no change to JDOQL (Andy's "alternative"). The
query language already protects against accidentally dereferencing null values
and provides for comparing values for null.
This proposal allows users to model persistent classes with possible null
valued fields using the shorthand Optional features. It seems to me that
Optional really is just a slick way to avoid using ==null and instead use
ifPresent and other object-oriented methods.
> 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)