2013年11月21日星期四

null! = xxx and xxx! = null What is the difference ?

null! = xxx and xxx! = null What is the difference ?
------ Solution ---------------------------------------- ----
this specification are many allusions , such as one of them, because programmers easy to == mistakenly written as =
If you put in front of the constant 5 = i, will compile errors , so you can find this typo bug


------ For reference only ---------------------------------- -----
first written more stringent to ensure xxx is not null
------ For reference only ------------------- --------------------
no any difference !
------ For reference only ------------------------------ ---------
no difference
------ For reference only ------------------------ ---------------
beans flavored with aniseed fennel word has several written
------ For reference only ----------- ----------------------------
no difference
------ For reference only ---- -----------------------------------
but I was head of the latter scolded - - said to be like the first to write tangled as it ~ ~ ~ depressed
------ For reference only --------------- ------------------------
your head may not be familiar , you should not criticize
But since the curse , and you do not get angry , because he was not familiar
------ For reference only -------------------- -------------------

encounter an unfamiliar java head no way
------ For reference only - -------------------------------------
I 've seen this before , it should be like the first One way to write , but I also do not forget the reason, heroes come popularize it.
------ For reference only -------------------------------------- -
XXX What is a variable ? Or something else ?
------ For reference only -------------------------------------- -
not the same thing ......
------ For reference only ---------------------------- -----------
did not make any difference.
------ For reference only -------------------------------------- -
no difference
------ For reference only -------------------------------- -------
1. java library to see how the code is written. Such as the String class ,

 public static String valueOf(Object obj) {
        return (obj == null) ? "null" : obj.toString();
    }

2.http :/ / www.google.com.hk / codesearch, search for null! = lang: java, see everyone is how to write .
------ For reference only -------------------------------------- -
lacks distinction , do not be too harsh
------ For reference only --------------------------- ------------

variables must be of ~ ~

------ For reference only ---------------------------------- -----
tomorrow Results posted ~
------ For reference only -------------------------- -------------


agree

some people when his head, but his stomach no goods, we had to take this stuff to scare people want to use this tree Granville
------ For reference only ------ ---------------------------------
no difference.
------ For reference only -------------------------------------- -
this thought ! good landlord ah

------ For reference only ---------------------------------- -----
may be the norm , constants in the former, the variable in the post.
------ For reference only -------------------------------------- -
prevent programmers write omission equals cause errors. null! = XX so less ! Will be given. The XX! = null less ! Would not be a
------ For reference only ---------------------------------- -----
this thought ! good landlord ah
------ For reference only --------------------- ------------------
are not equal this method. .
this method are different.
you such wording . There should be no distinction between the bar. .
look at the following answer
------ For reference only ------------------------- --------------
crap , i = 5 into if there is not an error ? !



------ For reference only ---------------------------------- -----
java in writing no difference between these two

------ For reference only ---------------------------------- -----
constant in the former, the variable in the post.
------ For reference only -------------------------------------- -
from meaning there will be no difference from the norm in terms of programming , the first one was written in order to prevent write : null = xxx
------ For reference only ------ ---------------------------------
on the landlord to raise this issue , it should be possible Both spellings .
A situation like this:
object A.equals ("") is usually best written as "". equals (A), because A If null, easy throws NullPointerException
- ---- For reference only ---------------------------------------
in some cases, the latter returns a null pointer , you try , and the first one that does not report a null pointer error
------ For reference only ------------- --------------------------
generally the case, but is used to determine equal "==" , the use of null == xxx, to prevent the == mistakenly written as an assignment =
As ! = no need to be so entirely designed ! The effect is the same, you really ***** head .
------ For reference only -------------------------------------- -
first written wording better than the second , most of the actual item inside the code is written with the first one , the first than the second rigorous
------ For reference only ---------------------------------------
String sss = null
sss == null and null == sss no difference

obj.someMethod () == null and null == obj.someMethod () there is a difference
because obj is null null pointer exception thrown when the former , the latter will not

landlord know ?
------ For reference only -------------------------------------- -
seems no different
------ For reference only ------------------------------- --------


think about it, is that right ?
Do not fraught

if obj is null, no matter what the wording will be free pointer ; if obj is not null, will perform two written someMethod method, so if the first way to write empty pointer exception , then certainly the second wording will empty pointer exception , two written simply no difference



------ For reference only ---------------------------------- -----
fact, no difference is the first one can prevent you ! Forget about because you have forgotten ! a compilation error will not logical errors. So easy correction
------ For reference only ---------------------------------- -----


This is the difference
------ For reference only ------------------------------- --------
c / c + + , there are conditions to prevent the judge erroneously written assignment function , java there is no difference
------ For reference only -------- -------------------------------
null! = xxx and xxx! = null does not difference
"abc". equals (xxx) and xxx.equals ("abc") differentiated
------ For reference only ---------- -----------------------------
no difference between right
------ For reference only --- ------------------------------------
only to prevent a typo put it like 23 F . Constant = variable , because the variable = constant correction seems to be forever really that much trouble ,
------ For reference only ------------------- --------------------
we habitually use the first to write side , such an approach is not easy to go wrong when a value is null , may be judged often being given , it should be placed in front of the null , so even if a variable is null behind not being given in the specific practice if there is such a mistake can think about is not for this reason
------ for reference only ---------------------------------------
no difference
------ For reference only --------------------------------------- < br> on your head over some of the java Refbacks Division, Jean Hall and there were discussed the issue because in order to avoid major mistakes xxx is the variable with the former, it is not easy to make mistakes ; the compiler will complain even if error this error is mainly down " ! " No. but the second , then you forget the compiler will not complain if I do not know , oh so tell whether you can understand

------ For reference only ---------------------------------- -----
well, yes, that rigor , the first one is better
------ For reference only ----------------- ----------------------
this is mainly compile time error, for example, to determine whether x is equal to 1, there are two kinds of writing : x == 1 , 1 == x, but sometimes we wrong wrote x = 1,1 = x, which is the former wording of x = 1 is not being given , so it is difficult to find such an error , if it is behind a species , then the compiler will complain . So this is a matter of habit , usually develop 1 == x This style of writing is good.
------ For reference only -------------------------------------- -
  This reply was moderator deleted at 2011-04-25 10:11:14

------ For reference only ---------------------------------- -----
Oh, did not know there is this problem , really gain it.
------ For reference only -------------------------------------- -

so. Afraid == mistakenly written = , such as

if(val==null){/*...*/}
written
if(val=null)//不会报错

However, if the null EDITORIAL will error :
if(null=val)

------ For reference only ----------------------------------- ----
"if (val = null) / / will not complain ."


do not know is not terrible, terrible is opinionated

Will you go to try to see an error, Lv eggs


------ For reference only ---------------------------------- -----
haha. That is certainly differentiated learning PHP and C + +, JS 's
------ For reference only ------------------------- --------------
  This reply was moderator deleted at 2011-04-25 09:15:07

------ For reference only ---------------------------------- -----
If you are a java programmer, both the wording did not make any difference , of course, if you are a C / C + + is another matter , the former written in C / C + + is more robust !
------ For reference only -------------------------------------- -
use the first method if the wrong JDK can check it out. Better. Like sometimes if (x == 1) accidentally wrote if (x = 1) this is not an error. . Khan but also find their investigation . . . But written if (1 = x) the error because constants can not be directly assigned
------ For reference only --------------- ------------------------
first one is the most formal wording
------ For reference only --- ------------------------------------
 roof
------ For reference only ---------------------------------------
no difference , the head if you want to to how to how, head saying is not "wrong " drop
supplement , java is no difference , c / c + + is a difference drops
------ For reference only -------------------- -------------------


this is the java will complain , but most other languages ​​do not it, so encourage more rigorous way !
------ For reference only -------------------------------------- -
both written in C # which is wrong it
------ For reference only ---------------------- -----------------
null! = xxx and xxx! = null differentiated it !
I have encountered such a problem
with xxx! = null runtime error
then replaced with null! = xxx is not being given .

------ For reference only -------------------------------- -------
is to avoid null pointer chant ! Such a simple question . . Egg pain
------ For reference only ------------------------------------ ---


very responsible to tell you two ways for writing a null pointer exception will not

a null pointer exception was written by the equals method
------ For reference only ------------------- --------------------
guess you were born leader is C + + , C + +, in order to avoid if being assigned to write null! = ; x, in java and c # can only exist if the Boolean type , there is no problem.
------ For reference only -------------------------------------- -

sense ......
------ For reference only -------------------------- -------------
prevent leakage write ! result in an error
Similarly xxx == null should be written as null == xxx
------ For reference only --------- ------------------------------

top "if (val = null) / / will not complain " 51 F wrote java compiler used it
------ For reference only ------------- --------------------------

Ah you put that contact to me, I can help you Masi Zhesi !
------ For reference only -------------------------------------- -
wrong people reply Intuit more ......

do not do not play .....
------ For reference only ------------------------ ---------------


estimated that the brothers have not used eclipse ....
------ For reference only ----------------------- ----------------
in fact, it says if (val = null) does not complain is possible

Boolean b = null;
if (b = null);


so the future is not compiled in JDK1.5 error , but is a special case of the

------ For reference only ---------------------------------- -----
forehead , looks like I've also run into xxx! = null on the error , later changed to null! = xxx is not being given . Well , in order to rigorous proposals null! = Xxx it.
------ For reference only -------------------------------------- -
71 F
you have not tried
Boolean b = null;
if (b = null);

this is right for you ?
------ For reference only ------------------------------------ ---
  This reply was moderator deleted at 2011-04-25 13:30:26

------ For reference only ---------------------------------- -----
real time with the development of the first, second there may be a null pointer exception
------ For reference only ------------ ---------------------------
null! = XXX never come this way null pointer exception. Extreme Programming is also suggested wording
------ For reference only ------------------------------ ---------
this is a historical problem, now is not the problem
------ For reference only ----------------- ----------------------



+ +
------ For reference only --------------------------------- ------
course is the first friends. . This can be very convenient error. .
can not be left as NULL values ​​, so when you ! = Wrong when you can easily being given . . .
------ For reference only -------------------------------------- -
do not use c or c + + to look upon java

if (a = 1) {
  //这里是c/c++, 不会报错的, 而你的本意是想判断a是否等于1, 你应该写成a == 1。 为了让编译器提醒你,你写成1 == a 最好了, 如果你忘了写一个=号, 比如 1=a, 这时候是会报错的, 而a=1不会报错
}




if (a = 1) {
   // 这里是java, 编译器直接报错了, 所以各位javaer, 在写"=="表达式的时候不要把变量写在前面了, OK? 要知道java是很强大的, 你写1 == a 和 a == 1没有任何区别, 这2个表达式哪一个少写等号直接报错了
}



------ For reference only ---------------------------------- -----

compile correct runtime exception (NPE)
------ For reference only --------------- ------------------------


Most of the people like to write is parroting or c / c + + legacy wording

in java, xxx == null looked more comfortable , as well as " {" not a single new line

such wording in java, very alternative

------ For reference only --- ------------------------------------


People are not saying java language . C, C + + Of course, you can write


if (i = 5)

it.
------ For reference only -------------------------------------- -
constants can not be assigned , therefore null == xxx, if == mistakenly written = , then the compiler will pass ! Just a good habit to prevent obscure bug produces
------ For reference only ------------------------- --------------
norms
------ For reference only ------------------- --------------------
class A
{
public:
explicit A (int * a): m_a (NULL) {}

bool operator == (int * const a) const {
return (m_a == a);
}

private:
int * m_a;
};
------ For reference only -------------------------------- -------
with the first good
------ For reference only ---------------------- -----------------

no difference
------ For reference only -------------------------------- -------
order to prevent you from accidentally put "== " instead of " =" , such as:
If you write if (null = obj) it is certainly not pass compiled.
If you write if (obj = null) that can be compiled through . You can hardly find such errors .

But in the final analysis , just a habit.
------ For reference only -------------------------------------- -
landlord is not to ask fennel beans have several written ?
------ For reference only -------------------------------------- -
first wording is strictly prohibited ah good writing style
java inside if (p = null) ... is not being given
I decided to put on the left to avoid the constant low-level errors committed
------ For reference only --------------- ------------------------
I only know a little bit of norms "". equals () try to make you their values ​​on the back
------ For reference only -------------------------------- -------

Ma Wan have to explain why you ?
------ For reference only ---------------- -----------------------
estimate is between JAVA and other language problems, but writing specifications or not, I have more vegetables, waiting for you.
if (val = null) in java is definitely wrong .

------ For reference only ---------------------------------- -----
js you say is right, I think you might be understood backwards - because if (i == 5) and if (i = 5) is not an error, it 's likely to occur typo bug, but if you use the first way to write , even if the programmer to 5 == i write 5 = i , and will generate an error , thus avoiding the occurrence of clerical errors .
------ For reference only -------------------------------------- -
think Wan pressed the hand a little shiver is what results a =

------ For reference only ---------------------------------- -----
absolutely no difference
------ For reference only -------------------------- -------------
order to prevent

xxx == null written in the wrong

xxx = null

! = what will be written in the wrong ?
Haha
------ For reference only --------------------------------- ------
if (xx = null) will not complain ?
tested to answer , OK?
Here java
------ For reference only ---- -----------------------------------
no basic difference between friends do not worry about this

没有评论:

发表评论