what is the difference between null != object and object!=null [duplicate]

The first two are equivalent, but the “null != object” is an old practice from languages where it is valid to write “if (object = null)” and accidentally assign null to the object. It is a guard to stop this accident from happening.

The second whilst equivalent has the added advantage that if “something” is null you will not get a null reference exception whereas you would if you did: something”.equals(“”).

Leave a Comment