2015-11-01 15:41 GMT+01:00 Vitaly Davidovich <vita...@gmail.com>: > One could argue that this is perfectly sound to do given Optional is > readonly, we just can't express this variance cleanly in java (i.e. without > upcast). >
Sure, as in Scala's Option[+A]. I should have said "... from a **Java** type perspective ". Regards, Stefan > > On Nov 1, 2015 7:31 AM, "Stefan Zobel" <splitera...@gmail.com> wrote: >> >> 2015-11-01 1:12 GMT+01:00 Michael Nascimento <mist...@gmail.com>: >> > Hi Vitaly, >> > >> > Exactly, I was just trying to point out the method signature seems >> > broken >> > anyway. >> > >> > Regards, >> > Michael >> >> >> Hi Michael, >> >> I don't think the signature is broken. >> >> An Optional<StringBuilder> is not a subtype of Optional<CharSequence>. >> So even if the signature were >> >> public <R extends T> Optional<T> or(Supplier<Optional<R>> supplier) >> >> we'd have to upcast the result of supplier.get() to Optional<T> >> which appears to be wrong from a type perspective. >> >> >> Regards, >> Stefan >> >> >> >> > >> > On 31 Oct 2015 11:59, "Vitaly Davidovich" <vita...@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" <mist...@gmail.com> >> >> wrote: >> >>> >> >>> If this instance is an Optional<CharSequence> , passing an >> >>> Optional<StringBuilder> will fail to compile. >> >>> >> >>> Regards, >> >>> Michael >> >>> On 31 Oct 2015 11:21, "Stefan Zobel" <splitera...@gmail.com> wrote: >> >>> >> >>> > 2015-10-31 19:11 GMT+01:00 Remi Forax <fo...@univ-mlv.fr>: >> >>> > >> >>> > > Hi all, hi Paul, >> >>> > > >> >>> > > I've just seen that Optional.or is declared as >> >>> > > public Optional<T> or(Supplier<Optional<T>> supplier) { >> >>> > > instead of >> >>> > > public Optional<T> or(Supplier<? extends Optional<T>> supplier) >> >>> > > { >> >>> > > >> >>> > > regards, >> >>> > > Rémi >> >>> > > >> >>> > >> >>> > >> >>> > I don't get it. Optional is final anyway. Can you explain? >> >>> > >> >>> > Thanks, >> >>> > Stefan