ios 静音模式_静音设计模式
生活随笔
收集整理的這篇文章主要介紹了
ios 静音模式_静音设计模式
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
ios 靜音模式
您最近是否遵循Mute-Design-Pattern?編寫(xiě)了大量代碼? 例如
try {complex();logic();here(); } catch (Exception ignore) {// Will never happen heheSystem.exit(-1); }Java 8有一個(gè)更簡(jiǎn)單的方法!
只需將這個(gè)非常有用的工具添加到您的Utilities或Helper類:
public class Helper {// 18395 lines of other code here@FunctionalInterfaceinterface CheckedRunnable {void run() throws Throwable;}public static void mute(CheckedRunnable r) {try {r.run();}catch (Throwable ignore) {// OK, better stay safeignore.printStackTrace();}}// 37831 lines of other code here }現(xiàn)在,您可以將所有邏輯包裝在這個(gè)漂亮的小包裝中:
mute(() -> {complex();logic();here(); });做完了!
更好的是,在某些情況下,您可以使用方法引用
try (Connection con = ...;PreparedStatement stmt = ...) {mute(stmt::executeUpdate); }翻譯自: https://www.javacodegeeks.com/2016/02/mute-design-pattern.html
ios 靜音模式
總結(jié)
以上是生活随笔為你收集整理的ios 静音模式_静音设计模式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: junit5和junit4_JUnit
- 下一篇: 游戏备案暂停什么意思(游戏备案暂停)