0

The documentation on the Apex class Set is quite straightforward, but it omits to mention what happens if you create a set of some Apex class:

Set<MyApexClass> mySet = new Set<MyApexClass>();

Since sets cannot contain duplicate entries, in the case of MyApexClass, how can it tell whether two instances are to be treated as equal?

In Java, one would simply over-ride the equals(Object o) and hashCode() methods, and the Set implementation would use use those methods to check for duplicates. Is there a similar mechanism in Apex?

1 Answer 1

1

In answer to my own question - yes there is a similar mechanism. Here it is:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_maps_keys_userdefined.htm

Quite why this is not mentioned on the Set documentation I don't know.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .