Optional.or() doesn't use a wildcard in its signature

Stefan Zobel spliterator at gmail.com
Sun Nov 1 17:01:39 UTC 2015


2015-11-01 1:12 GMT+01:00 Michael Nascimento <misterm at gmail.com>:
> Hi Vitaly,
>
> Exactly, I was just trying to point out the method signature seems broken
> anyway.
>

Rethinking it, I believe you are right.

public <R extends T> Optional<T> or(Supplier<Optional<R>> supplier)

would be more general and still be sound type-wise.

There's a similar issue for Stream generate / iterate in the bugtracker
https://bugs.openjdk.java.net/browse/JDK-8132097


Thanks,
Stefan

> On 31 Oct 2015 11:59, "Vitaly Davidovich" <vitalyd at gmail.com> wrote:
>>
>> This would require Supplier<Optional<? extends T>>, not Supplier<? extends
>> Optional<T>>.
>>
>> sent from my phone
>>
>> On Oct 31, 2015 2:49 PM, "Michael Nascimento" <misterm at gmail.com> wrote:
>>>
>>> If this instance is an Optional<CharSequence> ,  passing an
>>> Optional<StringBuilder> will fail to compile.
>>>
>>> Regards,
>>> Michael



More information about the core-libs-dev mailing list