Should you use the equals method or compare the event type IDs for EventType in Esper?

StackOverflow https://stackoverflow.com/questions/15255939

  •  18-03-2022
  •  | 
  •  

문제

I am trying to check if two of Esper's EventType objects are equal. By equal I mean that they are the same event types with the same properties.

I was wondering what is the best way to do it. Is it safe to use the equals method, like this:

eventType.equals(otherEventType)

As EventType is an interface, I cannot be sure that all the implementing classes will override the equals method. Because of this I assume the above code is not a good idea.

The other option that I can think of is to compare the event type IDs, like this:

eventType.getEventTypeId() == eventType.getEventTypeId()

However, I am not sure how these IDs are assigned. Will this give me what I am looking for, or is there better way?

도움이 되었습니까?

해결책

Event type id is a unique id per type thus not suitable. "Equals" is also not suitable. Since it depends on application semantics whether a type is the same or not you need to write your own compare.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top