Getting issue in validating the hands on challenge with the below error: The constructor MyIterable should accept parameter of type List<String>.
Here's my code snippet:
public class MyIterable implements Iterable<String>{ private List<String> strings; public MyIterable(List<String> strings){ this.strings= strings; } public Iterator<String> iterator() { return strings.iterator(); }}
I spent half a day trying to figure out why this error appears. The cause of the problem is very simple, a space between the method name and the opening bracket
There are a few other issues with the way the challenge gets parsed which cause the challenge to get failed, without being relevant to the result.
1. Defining the Myiterable constructor with an input parameter which is not literally named "strings".
2. Having brackets round the strings.iterator() return value in the Iterator method
3. In the test class, instantiating the MyIterable class within the for loop instead of a separate variable.
For 3. though, the release notes article for this feature uses exactly that for loop sysntax:
for (String str : new MyIterable()) {
System.debug(str);
}