I am pretty sure that I am missing something obvious here, but I still cannot grasp the casting operation in the following piece of code:
Set<String> mySet = new Set<String>();
mySet.add('One');
mySet.add('Two');
String mySet_Joined = String.join((Iterable<String>) mySet, ', ');
I read this post Do Apex collections implement iterable?, where we saw that Set does not implement either Iterable, nor Iterator interface.
System.debug((new set<String>()) instanceOf Iterable<Object>);
DEBUG|false
System.debug((new set<String>()) instanceOf Iterator<Object>);
DEBUG|false
Then I looked at this documentation article Classes and Casting and realized that in order to be cast to Iterable<String>
mySet must implement Iterable
. So I would expect exception to be thrown when this line gets executed (Iterable<String>) mySet
, but it is not.
Can someone please explain how that is possible?