实现迭代器接口的类 [英] Class which implements iterator interface
本文介绍了实现迭代器接口的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class SportCarHouse implements CarIterator {
List sportsCars;
public List getCars()
{
return sportsCars;
}
public Iterator createIterator()
{
return sportsCars.iterator();
}
}
我已经获得了实现Iterator接口的上述代码,但是遇到了以下错误.
I''ve got the above code which implements the Iterator interface, but I get the following errors.
C:\Documents and Settings\20818781\Desktop\Pattern_iterator\SportCarHouse.java:4: cannot find symbol
symbol : class List
location: class SportCarHouse
List sportsCars;
^
C:\Documents and Settings\20818781\Desktop\Pattern_iterator\SportCarHouse.java:19: cannot find symbol
symbol : class List
location: class SportCarHouse
public List getCars()
^
2 errors
推荐答案
与以前的Iterator
类一样,请尝试导入List
类:
import java.util.List
哦,等等,把它刮开.更好:
import java.util.*;
As with theIterator
class before, try importing theList
class:
import java.util.List
Oh, wait, scratch that. Even better:
import java.util.*;
这篇关于实现迭代器接口的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文