Java HashMap not finding key, but it should

后端 未结 4 1905
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 08:17

I have a strange issue occuring in my application, I will quickly explain global architecture and then my problem in depth.

I use a service to populate a HashM

4条回答
  •  囚心锁ツ
    2020-12-18 08:24

    Is your DomainObject class immutable? Does it have properly implemented hashCode and equals methods?

    Note that you will get into trouble if your DomainObject class is not immutable and you change the state of the object while it is in the map in a way that would change the result of calling hashCode or equals.

    hashCode must be implemented in such a way that it returns the same value for two objects whenever equals returns true when comparing these objects. See the API documentation of java.lang.Object.hashCode() for detailed information.

提交回复
热议问题