空检查编码标准 [英] Null check coding standard

查看:127
本文介绍了空检查编码标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于编码一个空检查标准的一个疑问。 我想知道的。

I have a doubt regarding coding standard of a null check. I want to know the difference between

if(a!=null)

if(null!=a)

哪一个更好,使用哪一个,为什么?

which one is better,which one to use and why?

推荐答案

两者都是在Java中一样,因为只有布尔EX pressions可能是内部的,如果这仅仅是一个编码风格通过编程器preference,其中大部分使用空!= A

Both are same in Java, as only boolean expressions can be inside an if. This is just a coding style preference by programmer and most of them use null != a.

空!= A 旧做法在如Java,C ++编程语言(称为尤达条件)。
因为它是有效的写若(a = NULL)时,不慎分配一个所以写首先是一名警卫阻止这起事故的发生

The null != a is an old practice in programming languages like Java,C++ (called as Yoda Conditions).
As it is valid to write if (a = null) and accidentally assign null to the a so writing null first is a guard to stop this accident from happening.

这篇关于空检查编码标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆