Do Apex collection classes implement Iterable interface? I want to write a generic function that can take any of the collection classes that support foreach. Is this possible?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Try the following code in v30:
So, in short, you need to handle each individually.
No, to my knowledge there is no way to use same code to iterate over Lists, Sets and Maps. You would have to provide 3 different entry points for your logic (override methods with different parameters perhaps) and wrap the rest in a function.
Additionally, you won't be able to reuse your code for anything other than sObjects or your custom object hierarchy since Salesforce doesn't support parametrised interfaces after api v26.0 (see comments to the answer of this question)
Not sure when it was introduced and it is not documented but
Writing methods that accept a