==和Equal()
equal
2023-09-14 09:07:38 时间
1.a==null与 null==a
null放在前面就是为了避免变量为空时 引了空指针异常
如: if(a==null) 如果a 真为空时,现在就相当用调用了变量a的方法,a 都为空了还调用他的方法,当然会引发空指针异常了,但写成if(null==a)就不会了
2、关于str.equal(“abc”)和”abc”.equal(str)
这个好像争论也挺多的,第一种常量写在后面可能符合大多数人的习惯,也符合我们的逻辑思维。但是需要多一个str是否为null的判断。否则这里是有可能出现异常的。而后一种写法不需要多做关于是否为null这个判断。就我个人喜好来说,比较喜欢后一种写法。
相关文章
- Springboot admin 发送邮件失败:com.sun.mail.smtp.SMTPSenderFailedException: 553 Mail from must equal authorized user
- 【BBED】使用bbed解决 the amount of space used is not equal to block size
- js函数 eql,equal,equalp
- 【总结 】550,535,553 Mail from must equal authorized user— jenkins(hudson) email163邮箱和26邮箱成功配置总结
- 【原创】Erlang 之 match 和 compare equal
- 【总结 】550,535,553 Mail from must equal authorized user— jenkins(hudson) email163邮箱和26邮箱成功配置总结
- 【RF库Collections测试】Dictionaries Should Be Equal
- 成功解决xgboost.core.XGBoostError: b‘value 0 for Parameter num_class should be greater equal to 1‘
- 成功解决ValueError: Dimension 1 in both shapes must be equal, but are 1034 and 1024. Shapes are [100,103
- PAT 1060 Are They Equal[难][科学记数法]