The new Guava 10 Optional states that it is naturally covariant and therefore can be launched.
If I try, it looks a little ugly:
Optional<Integer> opti = Optional.of(42); Optional<Number> optn = (Optional) opti;
I like to see some useful function like:
static <T> Optional<T> transform(Optional<? extends T> opt, Class<T> clazz);
(how to express this as a member function optional?)
Is it even possible to define an object of a transformation function, for example:
static <T> Function<Optional<? extends T>, Optional<T>> transformer(Class<T> class);
to convert a Collection<Optional<Double>>
to Collection<Optional<Number>>
without creating new objects for each?
I think that even the returned Function object can be implemented using an internal singlet.
source share