V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  facelezz  ›  全部回复第 5 页 / 共 5 页
回复总数  83
1  2  3  4  5  
2020-09-08 19:34:16 +08:00
回复了 brucefu 创建的主题 Java 多大厂才能用到分布式事务
@cinlen 人肉补偿属于“高阶最终灵活可能不太一致的一致性”
2020-08-13 10:06:24 +08:00
回复了 javaWeber 创建的主题 Java 请教下 java8 的 Optional。。
楼上回答了那么多,其实 guava 文档里就有解释。
Besides the increase in readability that comes from giving null a name (增加了可读性,isPresent()比 if xxx!=null 可读性好)
the biggest advantage of Optional is its idiot-proof-ness.It forces you to actively think about the absent case if you want your program to compile at all, since you have to actively unwrap the Optional and address that case (使用了 option 后,强迫你思考不存在的情况,避免忘记)

This is especially relevant when you're returning values that may or may not be "present." You (and others) are far more likely to forget that other.method(a, b) could return a null value than you're likely to forget that a could be null when you're implementing other.method. Returning Optional makes it impossible for callers to forget that case, since they have to unwrap the object themselves for their code to compile.

(对设计的优化,如果你的方法返回值可能存在也可能不存在,就尽量返回 optional,这样别人用你的方法就知道需要判断)
至于 orElse 这种类型操作,我自己理解的是 4 楼那样,此外,optional 并不是用来简化流程,只是一种设计,让人记住去处理 null
2020-07-21 19:00:30 +08:00
回复了 Email 创建的主题 Apple 上个月攒了台黑苹果 ITX,经过个把月使用很稳定,分享一下
看起来很精致,显示器是? opencore 很好用,跟着教程走一次到位,我的是 amd 2600+rx580 。
1  2  3  4  5  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3287 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 12:55 · PVG 20:55 · LAX 05:55 · JFK 08:55
Developed with CodeLauncher
♥ Do have faith in what you're doing.