Why does default == implementation not call Equals?
.net, c#, java
Solution
I believe the main reason is `==` is a static operator and can be called on `null` objects while `Equals` requires an instance.
For example:
Foo foo1 = null;
Foo foo2 = null;
Console.WriteLine(foo1 == foo2); // cannot use Equals
Problem
Possible Duplicate: Why ReferenceEquals and == operator behave different from Equals The default implementation of `==` operator compares objects by references. So when you override Equals (which default behaviour is the same) you have to also specify `==` and `!=` operators so that they call Equals (and make it in every class of hierarchy as `==` and `!=` operators are not virtual). My question is why it is so? Why does `==` and `!=` compare objects by reference instead of using Equals? I guess there should be a reason for such a fundamental thing. Update. To comments: I assumed `==` should depend on Equals (but not vice versa) as you can override Equals in base class and use this implementation in derived classes automatically. It wouldn't work if Equals used `==` in its implementation, as `==` is not virtual.