Skip to main content Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.
error

We made a wrong turn. Try again.

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();   }}

 

#Trailhead Challenges

9 answers
  1. Feb 16, 9:53 AM

    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);

    }

0/9000