What is the difference between doing the below in java?
In some languages, the if (null == object) pattern helps to avoid this mistake:
if (object = null)
... which accidentally trashes the value of the object variable.
But in Java, an if statement requires a condition expression whose type is boolean, and the type of object == null is NOT boolean. Hence that particular mistake / typo is guaranteed to give a compilation error.
Digression ...
The case where you plausibly could get into trouble with '==' versus '=' in classic Java is this:
if (flag == true)
or
if (flag == false)
However, no experienced Java programmer would write that. Instead they would write:
if (flag)
and
if (!flag)
With Java 5 and onwards, autoboxing of Boolean can get you into trouble. However, in that case you are doing something that is inadvisable anyway. Consider this:
Boolean TRUE = true;
Boolean TOO_TRUE = new Boolean(true); // generates a new instance ...
if (TRUE == TOO_TRUE) { // should be TRUE.equals(TRUE)
....
}
Again, an experienced programmer would avoid using boxed types unnecessarily, and avoid testing them with ==. Besides, you would probably get a warning for this from an IDE or from a static anaylser like FindBugs or PMD.
null == objectinstead? Provide your source so we see the context.