public final class InvokeProxy extends Object
对 try-catch 的异常处理方式进行了包装,当需要调用会抛出异常的方式时,例如:
public File getFile(String filename) throws NoSuchFileException {
// some code ...
}
调用时 InvokeProxy.fun(fileUtils::getFile).call("filename") , 这样完成调用。
这里 fun() 的参数是要调用方法,call() 的参数是要调用的方法的实际参数。
当方法抛出异常时,call() 调用返回 null,这里提供一些便捷的操作:
- 添加异常处理器:
- 调用方法时抛出异常时指定默认值:FunctionDesc.NonRtnMethod.xAddHandle(Class, Consumer)
- 使方法返回的结果用Optional包装返回:FunctionDesc.Rtn0pWrapper.addHandle(Consumer)
| 构造器和说明 |
|---|
InvokeProxy() |
| 限定符和类型 | 方法和说明 |
|---|---|
static FunctionDesc.NonRtn0pWrapper |
fun(FunctionDesc.NonRtn0P nonRtn0P) |
static <T> FunctionDesc.NonRtn1pWrapper<T> |
fun(FunctionDesc.NonRtn1P<T> nonRtn1P) |
static <T1,T2> FunctionDesc.NonRtn2pWrapper<T1,T2> |
fun(FunctionDesc.NonRtn2P<T1,T2> nonRtn2P) |
static <T1,T2,T3> FunctionDesc.NonRtn3pWrapper<T1,T2,T3> |
fun(FunctionDesc.NonRtn3P<T1,T2,T3> nonRtn3P) |
static <T1,T2,T3,T4> |
fun(FunctionDesc.NonRtn4P<T1,T2,T3,T4> nonRtn4P) |
static <R> FunctionDesc.Rtn0pWrapper<R> |
fun(FunctionDesc.Rtn0P<R> rtn0P) |
static <R,T> FunctionDesc.Rtn1pWrapper<R,T> |
fun(FunctionDesc.Rtn1P<R,T> rtn1P) |
static <R,T1,T2> FunctionDesc.Rtn2pWrapper<R,T1,T2> |
fun(FunctionDesc.Rtn2P<R,T1,T2> rtn2P) |
static <R,T1,T2,T3> |
fun(FunctionDesc.Rtn3P<R,T1,T2,T3> rtn3P) |
static <R,T1,T2,T3,T4> |
fun(FunctionDesc.Rtn4P<R,T1,T2,T3,T4> rtn4P) |
public static <R> FunctionDesc.Rtn0pWrapper<R> fun(FunctionDesc.Rtn0P<R> rtn0P)
public static <R,T> FunctionDesc.Rtn1pWrapper<R,T> fun(FunctionDesc.Rtn1P<R,T> rtn1P)
public static <R,T1,T2> FunctionDesc.Rtn2pWrapper<R,T1,T2> fun(FunctionDesc.Rtn2P<R,T1,T2> rtn2P)
public static <R,T1,T2,T3> FunctionDesc.Rtn3pWrapper<R,T1,T2,T3> fun(FunctionDesc.Rtn3P<R,T1,T2,T3> rtn3P)
public static <R,T1,T2,T3,T4> FunctionDesc.Rtn4pWrapper<R,T1,T2,T3,T4> fun(FunctionDesc.Rtn4P<R,T1,T2,T3,T4> rtn4P)
public static FunctionDesc.NonRtn0pWrapper fun(FunctionDesc.NonRtn0P nonRtn0P)
public static <T> FunctionDesc.NonRtn1pWrapper<T> fun(FunctionDesc.NonRtn1P<T> nonRtn1P)
public static <T1,T2> FunctionDesc.NonRtn2pWrapper<T1,T2> fun(FunctionDesc.NonRtn2P<T1,T2> nonRtn2P)
public static <T1,T2,T3> FunctionDesc.NonRtn3pWrapper<T1,T2,T3> fun(FunctionDesc.NonRtn3P<T1,T2,T3> nonRtn3P)
public static <T1,T2,T3,T4> FunctionDesc.NonRtn4pWrapper<T1,T2,T3,T4> fun(FunctionDesc.NonRtn4P<T1,T2,T3,T4> nonRtn4P)
Copyright © 2021. All rights reserved.