Expose the Object's hashCode() method in apex.
As we all know the java HashMap and HashSet collections rely on the Object's hashCode() method to generate a unique hash per object, and as apex supports these collections types somewhere in the platform code every apex object has to have this method implemented.
In fact, if you look in the debug log you can see a unique hex code for every object on memory.
There are times where this hashCode method would be useful to apex developers, for instance in the context of a visualforce page:
I have a visualforce page used for creating sObjects (so none of them have IDs yet) with a list of child objects to create. As there's no ID on these objects if I wanted to "delete" one from the page I have to know the list index, which is harder than it sounds to include without something like javascript.
However, if I could call the hashCode method on these sObjects I could iterate through the list and remove the sObject with the proper hash code.
The bottom line, without hashCode() there's no serializeable way to test object equality, which can be a hinderance in visualforce or batch apex in some cases.
0 comments
| Posted by Chris Peterson to Force.com Platform, Apex & Visualforce 15 hours ago