
我先来,引用别人的 jar 包时,看到源码还能这么玩。。。
if (deviceInfoModel == null || (deviceInfoModel.getDevices() == null || deviceInfoModel.getDevices().size() == 0)) { try { throw new DeviceNotFoundException("Android Device Not Found !!!"); } catch (DeviceNotFoundException e) { System.err.println(e.toString()); } } 这 throw 了又 catch,秀操作呢?!
大伙说说遇到过的惊艳代码,任何语言都可以
1 cjh1095358798 Jul 6, 2020 感觉很牛皮啊 |
2 neroransom Jul 7, 2020 via Android 层 层 外 包 |
3 drizztdu Jul 7, 2020 via iPhone 手动套娃 |
4 Still4 Jul 7, 2020 我见过这么用的,人家给我的解释是需要知道堆栈 |
5 matepi Jul 7, 2020 如果 if 内部是个异常处理的通用做法,这个很可以理解 但这个就是个 throw……要么就是准备以后写成通用做法,暂且这样写,后面便于批量找到后重构吧 ……编不下去了 |
6 timothyye Jul 7, 2020 左手抛出异常,右手立马接住,把异常玩弄于鼓掌之间 |
7 LongMaoz Jul 7, 2020 一朋友的: if(res.data.Msg === "成功"){ message.Show("成功") } |
8 supuwoerc Jul 7, 2020 我看到过这样的: ` if(a===true){ a=false; }else{ a=true; } ` |
10 ragnaroks Jul 7, 2020 csharp 的 public async Task ActionAsync(){ // } public async Task Invoke(){ await Task.run(async()=>{ await this.ActionAsync(); }); } |
11 ragnaroks Jul 7, 2020 好像被 trim 了,csharp 的 public async Task ActionAsync(){ ____// } public async Task Invoke(){ ____await Task.run(async()=>{ ________await this.ActionAsync(); ____}); } |
13 wmhx Jul 7, 2020 检测一个字符串是不是数值, 最简单的方法不就是 Integer.valueof() 看有没有异常么? |
14 35aZ4P8mT576683q Jul 7, 2020 interface Status { success: boolean; failure: boolean; } const result: Status = { success: true, failure: false } if (!data) { result.success = false; result.failure = true; } //Typescript 代码,如何把布尔值复杂化 //为了可以用 const 关键字不择手段 |
15 bigNewsMaker Jul 7, 2020 via iPhone #define ";" ";" |
16 Anarchy Jul 7, 2020 我猜啊,可能原来是需要打印堆栈的,后来改了 |
17 Ahaochan Jul 8, 2020 public class PrivilegeProvider { public String selectById(final Long id){ return new SQL(){ { SELECT("id, privilege_name, privilege_url"); } }.toString(); } } Mybatis 的源码,第一次看时居然没有看懂. https://blog.ahao.moe/posts/Ignored_initialization_block.html |
18 122006 Jul 31, 2020 new DeviceNotFoundException 里有逻辑呗。。。。 |