Implementing the Iterable interface

后端 未结 4 1892
星月不相逢
星月不相逢 2020-12-21 00:49

I just found this exam question in an old exam paper and am readying myself for an upcoming exam. I cannot figure it out :

The following depicts a contrived partial

4条回答
  •  死守一世寂寞
    2020-12-21 01:21

    The easiest thing to do would probably be to create a new ArrayList() populated with the values in things, and return the result of a call to its .iterator() method. That's certainly what I'd do in a situation with limited time (like an exam), and quite likely what I'd do in a real-world scenario, just to keep things simple.

    You could write your own ArrayIterator class, or use one from various libraries you can find around the web, but it seems like that would add unnecessary complexity.

提交回复
热议问题