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
  •  | 
  •  

Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top