Diamond in type patterns?

Florian Weimer fw at deneb.enyo.de
Mon Jan 4 22:24:01 UTC 2021


* Remi Forax:

> Should we allow the diamond syntax in a cast ?

I think it would be particularly useful for lambdas.  E.g. if Java
gains a parallel set of function interfaces that can throw IOException
(translating it to UncheckedIOException for the implemented
traditional functional interfaces), one could write

  (IOSupplier<>) () -> Files.newBufferedReader(path)

to obtain an IOSupplier<BufferedReader> that is also a
Supplier<BufferedReader>.

Without the cast, one would have to add convience functions

    static <T> IOSupplier<T> of(IOSupplier<T> supplier) {
        return supplier;
    }

and write:

  IOSupplier.of(() -> Files.newBufferedReader(path))

But maybe that's good enough.


More information about the amber-spec-observers mailing list