[infinispan-dev] Strategy to adopting Optional in APIs

Sanne Grinovero sanne at infinispan.org
Thu Mar 30 17:08:19 EDT 2017


I'm for "at discretion" and "avoid if not really needed" : not cool to
allocate objects for no reason.

On 30 Mar 2017 16:57, "Radim Vansa" <rvansa at redhat.com> wrote:

> Hi,
>
> I was wondering what's the common attitude towards using Optional in
> APIs, and what naming pattern should we use. As an example, I dislike
> calling
>
> if (entry.getMetadata() != null && entry.getMetadata().version() != null) {
>      foo.use(entry.getMetadata().version())
> }
>
> where I could just do
>
> entry.metadata().flatMap(Metadata::optionalVersion).ifPresent(foo::use)
>
> Here I have proposed metadata() method returning Optional<Metadata>
> (regular getter method is called getMetadata()) and annoying
> optionalVersion() as version() is the regular getter.
>
> Shall we adopt some common stance (use/don't use/use at developer's
> discretion) and naming conventions? Is it acceptable to start adding
>
> default Optional<Foo> foo() { Optional.ofNullable(getFoo()); }
>
> whenever we feel the urge to chain Optionals?
>
> Radim
>
> --
> Radim Vansa <rvansa at redhat.com>
> JBoss Performance Team
>
> _______________________________________________
> infinispan-dev mailing list
> infinispan-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/infinispan-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/infinispan-dev/attachments/20170330/154e15cd/attachment-0001.html 


More information about the infinispan-dev mailing list