[
https://issues.apache.org/jira/browse/AVRO-1961?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15689789#comment-15689789
]
Niels Basjes commented on AVRO-1961:
------------------------------------
The idea is that the downstream application code becomes more readable when
retrieving a field that is buried deep in a nested structure.
With Optionals you can rely on the fact that there will always be a value
returned and this removes the need for having many {{if (foo != null)}} type
checks.
As you can see in the unit test I wrote you can do something like this:
{code}
assertEquals("Chrome 123", Optional
.of(request)
.flatMap(Request::getOptionalHttpRequest)
.flatMap(HttpRequest::getOptionalUserAgent)
.flatMap(UserAgent::getOptionalUseragent)
.orElse("UNKNOWN"));
{code}
> [JAVA] Generate getters that return an Optional
> -----------------------------------------------
>
> Key: AVRO-1961
> URL: https://issues.apache.org/jira/browse/AVRO-1961
> Project: Avro
> Issue Type: New Feature
> Reporter: Niels Basjes
> Assignee: Niels Basjes
> Priority: Minor
>
> A colleague of mine indicated that having getters that return an Optional
> (java 8 thingy) would be very useful for him.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)