AtomicReference | int 和long类型转化 | Optional.ofNullable
AtomicReference参考网址:https://www.jianshu.com/p/5521ae322743 这个类在项目中有使用到过。
public static void main(String[] args) { AtomicReference atomicReference = new AtomicReference("first value referenced"); String a="丫丫丫"; for (int i = 0; i <10 ; i++) { a=a+"_"+i; String reference = (String) atomicReference.getAndSet(a+"y"); System.out.println(reference); } }
运行结果:
first value referenced
丫丫丫_0y
丫丫丫_0_1y
丫丫丫_0_1_2y
丫丫丫_0_1_2_3y
丫丫丫_0_1_2_3_4y
丫丫丫_0_1_2_3_4_5y
丫丫丫_0_1_2_3_4_5_6y
丫丫丫_0_1_2_3_4_5_6_7y
丫丫丫_0_1_2_3_4_5_6_7_8y
int 和 long类型互转:
public long say(int i) { return i+3; } public static void main(String[] args) { Test test = new Test(); System.out.println(test.say(1)); }
运行结果:4
可见int类型是能够自动转化成Long类型的。
Optional.ofNullable
参考网址:https://blog.csdn.net/zym_1321/article/details/107769743
Optional.ofNullable(object),//这是在判断不为空的时候会走的分支。