java - 实现 Iterator 的抽象类的实例不会迭代
问题描述
似乎当我有一个实现接口的抽象类时,扩展我的抽象类的主类没有拾取接口:
当我使用这个时:
public abstract class MusicIntCollection implements Iterator<Integer>{...}
我无法遍历 StepIndexCollection 的实例:
public class StepIndexCollection extends MusicIntCollection{...}
但是,当我创建这个时:
public class StepIndexCollection extends MusicIntCollection implements Iterator<Integer>{...}
...我可以遍历 StepIndexCollection 的一个实例。
这是我迭代的方式:
this.notes = new StepIndexCollection();
for (int i : o.notes()) {
this.notes.add(i);
}
有没有办法让它从抽象类工作,所以我所有扩展 MusicIntCOllection 的特定类类型也不必实现接口?
解决方案
推荐阅读
- html - Table Html 5 th td 问题
- algorithm - 可以使用 O(1) 或 O(log n) 来计算元素数量吗?
- android - 当应用程序在 Android 上中断时,我的“共享项目”中的课程会发生什么情况?
- python - 如何以编程方式告诉 matplotlib 绘图窗口保存和关闭
- sql - Oracle SQL 字符串以“987”或“I”开头
- node.js - 从计划的 Windows 任务调用时,节点的 spawn/exec 不工作
- laravel - Laravel Lighthouse Graphql belongsToMany 具有枢轴值的突变
- typescript - Rxjs 将 API 结果 Observable 转换为服务函数中的另一个 Observable
- python - Matplotlib:从保存图像的边缘删除白色边框
- css - Flexbox flex-direction 在 Firefox/IE/Edge 上隐藏滚动