Last active
June 29, 2022 02:19
-
-
Save friddle/bb33390f4070b01540e8d7a0a6d180fb to your computer and use it in GitHub Desktop.
Java Lambda Wrapper for Exception Java的Lambda一些Wrapper。模拟kt操作
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Slf4j | |
public class BizUtils { | |
public static<R> R invoke(Function<Void,R> function, R defaultValue){ | |
try { | |
return function.apply(null); | |
} catch (Exception e) { | |
log.error("try method failed", e); | |
return defaultValue; | |
} | |
} | |
public static String invokeS(Function<Void,String> function, String defaultValue){ | |
var result=invoke(function,defaultValue); | |
if(result.isEmpty()){return defaultValue;} | |
return result; | |
} | |
public static<T,R> R ignoreError(Function<T,R> function, T args) | |
{ | |
try { | |
return function.apply(args); | |
} catch (Exception e) { | |
log.error("try method failed", e); | |
return null; | |
} | |
} | |
} | |
//File file=BizUtils.invoke(item->new File("xxxx"),aaaa); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment