Difference between Equals/equals and == operator?

前端 未结 11 997
一生所求
一生所求 2020-11-22 14:14

What is the difference between a == b and a.Equals(b)?

11条回答
  •  佛祖请我去吃肉
    2020-11-22 15:11

    a == b returns true if the references contain the same value, i.e., they point to the same object, or they are both null.

    The equals() method can be overridden to compare objects. For example, on Strings, the method returns true if the strings contain the same string, even if they are different string objects. You can do similar things with your own objects.

    o.equals() will throw an exception if o is a null reference.

提交回复
热议问题