我有以下界面:
public interface DataSet<T> extends Iterable<T> {
public int nExamples();
public T getExample(int index);
public Iterator<T> iterator();
}
然后是一个实现这个接口的类:
public class StringTupleDataset implements DataSet<StringTuple> {
Vector<StringTuple> examples;
public StringTupleDataset(Vector<StringTuple> examples) {
if(examples == null)
throw new IllegalArgumentException("null parameter: examples");
this.examples = examples;
} // constructor
@Override
public int nExamples() {
return examples.size();
} // nExamples
@Override
public StringTuple getExample(int index) {
return examples.get(index);
} // getExample
@Override
public Iterator<StringTuple> iterator() {
return examples.iterator();
} // getAllExamples
} // class
该类StringTupleDataset
编译没有问题。
但是,当我尝试在另一个类中编写这段代码时:
public abstract class AbstractOntologyFiller<T> {
private AbstractOntologyFiller() {}
public static <T> void fill(OntologyManager ontoManager, DataSet<T> dataset) {
for(T e : dataset.iterator()) {
// do something
} // for
} // fill
} // class
我有一个编译错误说:
Can only interate over an array or an instance of java.lang.Iterable
有谁能帮助我吗?