随笔 | 奇淫技巧 | Java:记return和短路运算符的妙用
在阅读AtomicStampedReference的源码中,在compareAndSet()方法发现一段代码: return expectedReference == current.reference && expectedStamp == current.stamp && //上方条件全部符合且为True时,执行下方代码 ((newReference == current.reference && newStamp == current.stamp) || casPair(current, Pair.of(newReference, newStamp))); 即在return执行方法,并获取最终结果。我编写了一段代码用以测试: public class Main { public static void main(String[] args) { Main main = new Main(); System.out.println( main.executeIsTrue() ); System.out.println(); Sys....