Package art.cutils.function
Interface ThrowingFunction<T,R>
-
- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the function
- All Known Subinterfaces:
ThrowingUnaryOperation<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ThrowingFunction<T,R>
When you find yourself in a situation where you need to use a method ( that throws an exception) withing Lambda, this class is what you need to achieve your goal without Java complaining.The class Represents a function that accepts one argument and produces a result. whose functional method is
apply(Object)
.- Since:
- 1.0
- Author:
- , Bobai Kato
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description R
apply(T t)
Applies this function to the given argument.static <T extends Exception,R>
RsneakyThrow(Exception ex)
Sneak exception on function execution.static <T,R>
@NotNull Function<T,R>unchecked(ThrowingFunction<T,R> function)
Uncheck method which will take operation that will throw Exception.
-
-
-
Method Detail
-
unchecked
@NotNull static <T,R> @NotNull Function<T,R> unchecked(ThrowingFunction<T,R> function)
Uncheck method which will take operation that will throw Exception.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the function- Parameters:
function
- Variable ofThrowingFunction
- Returns:
- A
Function
-
apply
R apply(T t) throws Exception
Applies this function to the given argument.- Parameters:
t
- the function argument if Type T- Returns:
- the function result
- Throws:
Exception
- any exception thrown when applying function
-
sneakyThrow
@Contract(value="_ -> fail", pure=true) static <T extends Exception,R> R sneakyThrow(Exception ex) throws T extends Exception
Sneak exception on function execution.- Type Parameters:
T
- arg typeR
- return type- Parameters:
ex
- exception throw on operation- Returns:
- an exception
- Throws:
T
- arg type exceptionT extends Exception
-
-