哪个具有更好的性能:test!= null或null!= test

哪个具有更好的性能:test!= null或null!= test,第1张

哪个具有更好的性能:test!= null或null!= test

没有不同。

第二个原因仅仅是因为C / C ++程序员总是执行分配而不是比较。

例如

// no compiler complaint at all for C/C++// while in Java, this is illegal.if(a = 2) {}// this is illegal in C/C++// and thus become best practice, from C/C++ which is not applicable to Java at all.if(2 = a) {}

而java编译器会生成编译错误。

因此,由于可读性强,我个人更喜欢第一个,人们倾向于从左到右阅读,

if test is not equal to null
而不是
null is notequal to test



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5623344.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存