What is the difference between object !=null and null !=object?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karthickkuchanur
    New Member
    • Dec 2007
    • 156

    #1

    What is the difference between object !=null and null !=object?

    Dear Experts,

    Please let me know what is the difference between difference between object !=null and null !=object,I already google it but i can't able to find the right answer
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    It is the same test whichever way it is written.
    object != null is more intuitive when reading the code.

    But in some cases in some languages an error will be thrown if the object does not exist.
    Whereas the other way around null != object will not complain.

    I can't remember (Monday morning) exactly what the circumstances are, but null != object can be safer.

    Comment

    • karthickkuchanur
      New Member
      • Dec 2007
      • 156

      #3
      Actually ,this question is asked by manager ,I think there something behind this check ,there must be difference in java

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        In C++ where operators could be overwritten, this might make a difference. With Java objects, I think it just compares the addresses of the two.

        Comment

        Working...