Suppose I have an Optional<Exception>
and want to cast it to an Optional<Throwable>
. Are there any prettier ways of doing this rather than:
Optional<Exception> optionalException = Optional.of(new Exception());
Optional<Throwable> optionalThrowable = (Optional<Throwable>) (Optional<? extends Throwable>) optionalException;
This solution generates a lint warning in IntelliJ.
Unchecked cast: 'java.util.Optional<capture<? extends java.lang.Throwable>>' to 'java.util.Optional<java.lang.Throwable>'