How should one unit test the hashCode-equals contract?

前端 未结 8 1006
长发绾君心
长发绾君心 2020-12-07 13:18

In a nutshell, the hashCode contract, according to Java\'s object.hashCode():

  1. The hash code shouldn\'t change unless something affecting equals() changes
8条回答
  •  醉梦人生
    2020-12-07 13:41

    You can also use something similar to http://code.google.com/p/guava-libraries/source/browse/guava-testlib/src/com/google/common/testing/EqualsTester.java to test equals and hashCode.

提交回复
热议问题