Imo we are doing this wrong. The API would be much more readible with static
factory methods:
```
/**
* {@link Consumer} that can throw checked exceptions.
*/
@FunctionalInterface
public interface CheckedConsumer<T> {
void checkedAccept(T t) throws Exception;
static <T> Consumer<T> unchecked(CheckedConsumer<T> checkedConsumer) {
return (t) -> {
try {
checkedConsumer.checkedAccept(t);
} catch (Exception e) {
ExceptionUtils.rethrow(e);
}
};
}
}
```
This allows for:
```
CheckedConsumer.unchecked(isRecoveredJobRunning -> {
...
});
```
No casts are required. Also when interacting with the Java API, it does not
matter what exact type of exception can be thrown – what matters is that the
checked exception becomes a unchecked. We do not need to generify the exception
type in `ConsumerWithException`.
[ Full content available at: https://github.com/apache/flink/pull/6678 ]
This message was relayed via gitbox.apache.org for [email protected]