Throwing Functions

Nathan Reynolds numeralnathan at gmail.com
Sat Nov 12 04:47:10 UTC 2022


I am sorry if I am very late to the discussion.  Consumer, Function,
Predicate, and Supplier don't allow for throwing checked exceptions.  This
feature is needed in many cases.  What about adding a variant that allows
for throwing checked exceptions?  For example, a ThrowableConsumer could be
defined as such...

public interface ThrowableConsumer<T, E extends Throwable>
{
   void accept(T t) throws E;
}

A method that receives this as a parameter could be defined as such...

public <E extends Throwable> void process(ThrowableConsumer<T, E> consume)
throws E
{
   ...
}

The compiler takes care of ensuring the checked exception is dealt with in
the caller to process().
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20221111/c5d006ec/attachment.htm>


More information about the amber-dev mailing list