<div dir="auto">I'm for "at discretion" and "avoid if not really needed" : not cool to allocate objects for no reason. </div><div class="gmail_extra"><br><div class="gmail_quote">On 30 Mar 2017 16:57, "Radim Vansa" <<a href="mailto:rvansa@redhat.com">rvansa@redhat.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I was wondering what's the common attitude towards using Optional in<br>
APIs, and what naming pattern should we use. As an example, I dislike<br>
calling<br>
<br>
if (entry.getMetadata() != null && entry.getMetadata().version() != null) {<br>
foo.use(entry.getMetadata().<wbr>version())<br>
}<br>
<br>
where I could just do<br>
<br>
entry.metadata().flatMap(<wbr>Metadata::optionalVersion).<wbr>ifPresent(foo::use)<br>
<br>
Here I have proposed metadata() method returning Optional<Metadata><br>
(regular getter method is called getMetadata()) and annoying<br>
optionalVersion() as version() is the regular getter.<br>
<br>
Shall we adopt some common stance (use/don't use/use at developer's<br>
discretion) and naming conventions? Is it acceptable to start adding<br>
<br>
default Optional<Foo> foo() { Optional.ofNullable(getFoo()); }<br>
<br>
whenever we feel the urge to chain Optionals?<br>
<br>
Radim<br>
<br>
--<br>
Radim Vansa <<a href="mailto:rvansa@redhat.com">rvansa@redhat.com</a>><br>
JBoss Performance Team<br>
<br>
______________________________<wbr>_________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a><br>
</blockquote></div></div>