Interface FunctionExt<T,R,E extends java.lang.Throwable>
-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@PrimaryRequirement(updates=java.util.function.Function.class) @FunctionalInterface public interface FunctionExt<T,R,E extends java.lang.Throwable>
Changes for
FunctionWhy:
1. If a Function lambda throws a checked exceptions, then the developer has to messily wrap it in a RuntimeException.
2. If Function.apply throws a RuntimeException, then the compiler will not warn the developer.
3. This class provides type-safe exceptions, which is not currently possible with java.util.function classes.
To eliminate the need for this class:
1. Java should support default values for generic parameters.
2. Modifyjava.util.function.Function<T, R>toFunction<T, R, E extends Throwable = Throwable>
Risk:
1. Maintains source compatibility because the E parameter can be omitted.
2. Maintains binary compatibility because generic types are erased.
3. Impact on code using Reflection APIs should be minimal.
-
-
Method Summary
Modifier and Type Method Description default <V> FunctionExt<T,V,E>andThen(FunctionExt<? super R,? extends V,E> after)Rapply(T t)default <V> FunctionExt<V,R,E>compose(FunctionExt<? super V,? extends T,E> before)static <T> FunctionExt<T,T,java.lang.Throwable>identity()
-
-
-
Method Detail
-
apply
@Update R apply(T t) throws E extends java.lang.Throwable
- Throws:
E extends java.lang.Throwable
-
compose
@Update default <V> FunctionExt<V,R,E> compose(FunctionExt<? super V,? extends T,E> before)
-
andThen
@Update default <V> FunctionExt<T,V,E> andThen(FunctionExt<? super R,? extends V,E> after)
-
identity
@Update static <T> FunctionExt<T,T,java.lang.Throwable> identity()
-
-