equals(…) and equalsIgnoreCase(…)

后端 未结 7 927
遇见更好的自我
遇见更好的自我 2021-01-01 19:44

Why do we have equals() and equalsIgnoreCase() as two different methods, when equals() could have been overloaded with a special

7条回答
  •  无人及你
    2021-01-01 20:13

    The main test when overridng a method with additional parameters is that I would expect any method override to do exactly the same thing as the method it's overriding. Equals(), being derived from Object has a contract it must follow. Two objects that are equal() should have identical hashcodes. I don't think two objects that are case insensitive equal should have the same hashcode, so I believe overriding equal here is the wrong thing to do.

提交回复
热议问题